Chapter 3: Web Technology – Class 12 Computer Science Notes
Importantedunotes.com
Back to Computer Notes

Exercise 1: Choose the correct answer.

Select an option to view the correct answer and justification.

1. What is the correct syntax for a for-loop in JavaScript?
a) for (var i=0; i<5; i++)
b) for (i=5; i)
c) for (var i=0; i)
d) for (var i=5; i)
Correct Answer: a) for (var i=0; i<5; i++)
Justification: A JavaScript for-loop needs three parts — initialization, condition, and increment/decrement — separated by semicolons. Only option (a) has all three parts correctly structured.
2. Which PHP function is commonly used to execute SQL queries on a database connection established using extension?
a) mysqli_query()
b) pdo_query()
c) mysql_query()
d) pgsql_query()
Correct Answer: a) mysqli_query()
Justification: mysqli_query() is the modern PHP function used to run SQL queries on a database connection created with the MySQLi extension (the older mysql_query() is deprecated).
3. What function do you need to call to ask the user of the program to enter text in JavaScript?
a) readline()
b) readln()
c) text()
d) prompt()
Correct Answer: d) prompt()
Justification: prompt() displays a dialog box asking the user to input text and returns the entered value as a string.
4. Which JavaScript function is used for text input?
a) alert()
b) confirm()
c) prompt()
d) console.log()
Correct Answer: c) prompt()
Justification: alert() only displays a message, confirm() asks for OK/Cancel, and console.log() prints to the console — only prompt() actually accepts text input from the user.
5. Which of the following PHP functions is used to connect to a MySQL database?
a) mysql_connect()
b) mysqli_connect()
c) pdo_connect()
d) db_connect()
Correct Answer: b) mysqli_connect()
Justification: mysqli_connect() is the current, supported PHP function used to open a connection to a MySQL database server.
6. Which of the given signs is used as a shortcut for jQuery?
a) the % sign
b) the & sign
c) the $ sign
d) the @ sign
Correct Answer: c) the $ sign
Justification: In jQuery, the dollar sign ($) is an alias for the jQuery() function, e.g. $(“p”).hide() is the same as jQuery(“p”).hide().
7. Which jQuery method is used to hide selected elements?
a) hide()
b) invisible()
c) hide(slow)
d) display(none)
Correct Answer: a) hide()
Justification: The jQuery hide() method hides the selected elements. Options (b) and (d) are not valid jQuery methods, and (c) uses invalid syntax.
8. Which method is used to return today’s date and time in PHP?
a) Today date() method
b) Today’s date() method
c) Date() method
d) Today’s date and time() method
Correct Answer: c) Date() method
Justification: PHP’s date() function is used to format and return the current date and time based on a given format string.
9. What is the correct syntax for referring to an external JavaScript?
a) <script src=”nes.js”></script>
b) <java href=”nes”></java>
c) <script href=”nes.js”></script>
d) <script src=”neb.js”></script>
Correct Answer: a) <script src=”nes.js”></script>
Justification: External JavaScript files are linked using the <script> tag with the src attribute pointing to the file name, matching option (a) exactly.
10. What would be the value of “z” in the given code?
var x = 5; var y = 2; var z = x % y;
a) 1
b) 3
c) 2
d) 2.5
Correct Answer: a) 1
Justification: The % operator returns the remainder of division. 5 divided by 2 gives a quotient of 2 with a remainder of 1, so z = 1.
11. Which is the correct open tag and close tag for PHP Scripts?
a) <?php ?>
b) <? ?>
c) < ? >
d) <?php >
Correct Answer: a) <?php ?>
Justification: The standard PHP tag opens with <?php and closes with ?>, matching option (a).
12. What is the correct syntax for referring to an external JavaScript?
(Same question repeated in the original question set)
a) <script src=”nes.js”></script>
b) <java href=”nes”></java>
c) <script href=”nes.js”></script>
d) <script src=”neb.js”></script>
Correct Answer: a) <script src=”nes.js”></script>
Justification: Same as Question 9 — the src attribute inside the <script> tag is the correct way to reference an external JavaScript file.
13. Which of the following is the correct way to define a variable in PHP?
a) variable_name = value;
b) Variable_Name = value;
c) variable-name = value;
d) $variable_name = value;
Correct Answer: d) $variable_name = value;
Justification: In PHP, all variables must begin with a dollar sign ($) followed by the variable name, as shown in option (d).
14. JavaScript is an:
a) Procedural-oriented language
b) Object-oriented programming language
c) Firmware
d) None of the above
Correct Answer: b) Object-oriented programming language
Justification: JavaScript is built around objects and supports object-oriented concepts, making it an object-oriented programming language.
15. Data types in JavaScript are:
a) Primary and secondary
b) Primitive & non-primitive
c) None of the above
Correct Answer: b) Primitive & non-primitive
Justification: JavaScript data types are classified into primitive types (String, Number, Boolean, etc.) and non-primitive/reference types (Object, Array, Function).
16. PHP stands for:
a) Hypertext Pre-processor
b) Program Hyper Processor
c) Process Hyper Program
d) None of the above
Correct Answer: a) Hypertext Pre-processor
Justification: PHP is a recursive acronym officially standing for “PHP: Hypertext Pre-processor.”
17. concat() is a:
a) Integer method
b) Image method
c) String method
d) None of the above
Correct Answer: c) String method
Justification: concat() is used to join two or more strings together and return a new combined string, making it a String method.
18. A ________ is an identifier whose value may change during the execution of the program.
a) Constant
b) Function
c) Variable
d) None of the above
Correct Answer: c) Variable
Justification: A variable is an identifier used to store a value that can change during program execution, unlike a constant, whose value stays fixed.

Exercise 2: Write short answers to these questions.

a) What is a script? Write down the difference between client-side scripting and server-side scripting.

A ‘script’ means a piece of code that runs on the server or client.

The difference between Client-side and Server-side Scripting:

S.N.Client-side ScriptingServer-side Scripting
1This code is visible to the user.This code is not visible to the user.
2It runs on the client computer.It runs on the web server.
3This code does not require frequent interaction with the server.It needs frequent interaction with the server.
4It does not provide high security.It provides high security of data.
5It reduces the load on the server.It increases the load on the server and makes the contents dynamic.
6Comparatively, the code execution is faster.It is slower because it has to take the data to the server to process.

b) What is JavaScript? Write down the advantages of JavaScript.

JavaScript is the most popular and widely used client-side scripting language. JavaScript is designed to add interactivity and dynamic effects to webpages by manipulating the content returned from a web server.

Uses of JavaScript:

Client-side validation.
Displaying date and time.
To validate the user input before submission of the form.
Open and close new windows.
To display dialog boxes and pop-up windows.

Advantages of JavaScript:

One of the most popular scripting languages in the world.
Relatively quick and easy to learn.
Incredibly versatile.
Doesn’t make heavy demands on the server.
Immediate feedback to the visitors.
Increased interactivity.
Richer interface.
Less server interaction required.
Supported by all web browsers.
Gives responses to users immediately.
JavaScript is used in many applications.

Difference between Scripting Language and Programming Language:

S.N.Scripting LanguageProgramming Language
1Scripting languages are platform-specific.Programming languages are platform-independent.
2Most of the scripting languages are interpreted.Most programming languages are compiled.
3Scripting languages run slower than programming languages.Programming languages run faster than scripting languages.
4The developer has to write less code compared to a programming language.The developer has to write much code compared to a scripting language.

Exercise 3: WT Programming (JavaScript)

1. Write a JavaScript code to find if the given number is positive or negative by using a JS Function.
positive-negative.html
<!DOCTYPE html>
<html>
<head>
    <title>JS</title>
</head>
<body>
    Enter the number: <input id="num">
    <button onclick="PNC()">P/N</button>
    <p id="answer"></p>

    <script>
        function PNC() {
            var x = Number(document.getElementById("num").value);
            if (x > 0) {
                document.getElementById("answer").innerHTML = "The given number " + x + " is a positive number.";
            } else if (x < 0) {
                document.getElementById("answer").innerHTML = "The given number " + x + " is a negative number.";
            } else {
                document.getElementById("answer").innerHTML = "The given number " + x + " is zero.";
            }
        }
    </script>
</body>
</html>

2. Write a JavaScript code to find if the given number is odd or even by using a JS Function.
odd-even.html
<!DOCTYPE html>
<html>
<head>
    <title>JS</title>
</head>
<body>
    Enter the number: <input id="num">
    <button onclick="OddEven()">Odd/Even</button>
    <p id="result"></p>

    <script>
        function OddEven() {
            var n = Number(document.getElementById("num").value);
            if (n % 2 == 0) {
                document.getElementById("result").innerHTML = "The given number " + n + " is an even number.";
            } else {
                document.getElementById("result").innerHTML = "The given number " + n + " is an odd number.";
            }
        }
    </script>
</body>
</html>

3. Write a JavaScript function to enter two numbers and find the sum of the two numbers.
sum-two-numbers.html
<!DOCTYPE html>
<html>
<head>
    <title>JS</title>
</head>
<body>
    Enter the first number: <input id="num1">
    Enter the second number: <input id="num2">
    <button onclick="Sum()">Sum</button>
    <p id="result"></p>

    <script>
        function Sum() {
            var x = Number(document.getElementById("num1").value);
            var y = Number(document.getElementById("num2").value);
            var z = x + y;
            document.getElementById("result").innerHTML = "The sum of " + x + " and " + y + " is " + z + ".";
        }
    </script>
</body>
</html>

4. Write a JavaScript code to calculate the factorial of a given number.
factorial.html
<!DOCTYPE html>
<html>
<head>
    <title>JS</title>
</head>
<body>
    Enter the number: <input id="num">
    <button onclick="Fact()">Fact</button>
    <p id="result"></p>

    <script>
        function Fact() {
            var n = Number(document.getElementById("num").value);
            var f = 1;
            for (var i = 1; i <= n; i++) {
                f = f * i;
            }
            document.getElementById("result").innerHTML = "The factorial of the number " + n + " is " + f + ".";
        }
    </script>
</body>
</html>

5. Write a program to find the largest number among three numbers in JavaScript.
largest-number.html
<!DOCTYPE html>
<html>
<head>
    <title>JS</title>
</head>
<body>
    Enter the first number: <input id="num1">
    Enter the second number: <input id="num2">
    Enter the third number: <input id="num3">
    <button onclick="LargerNumber()">Larger Number</button>
    <p id="result"></p>

    <script>
        function LargerNumber() {
            var a = Number(document.getElementById("num1").value);
            var b = Number(document.getElementById("num2").value);
            var c = Number(document.getElementById("num3").value);

            if (a > b && a > c) {
                document.getElementById("result").innerHTML = "The given number " + a + " is the largest number.";
            } else if (b > a && b > c) {
                document.getElementById("result").innerHTML = "The given number " + b + " is the largest number.";
            } else {
                document.getElementById("result").innerHTML = "The given number " + c + " is the largest number.";
            }
        }
    </script>
</body>
</html>

6. Write a JavaScript code to find the addition of two numbers by using JS popup windows.
sum-popup.html
<!DOCTYPE html>
<html>
<head>
    <title>JS</title>
</head>
<body>
    Enter a first number: <input id="num1">
    Enter a second number: <input id="num2">
    <button onclick="Sum()">Sum</button>

    <script>
        function Sum() {
            var n1 = Number(document.getElementById("num1").value);
            var n2 = Number(document.getElementById("num2").value);
            var s = n1 + n2;
            alert("The sum of the two numbers is " + s);
        }
    </script>
</body>
</html>

7. Write a JavaScript code to find the sum of nth natural numbers by using a JS function.
sum-nth-natural.html
<!DOCTYPE html>
<html>
<head>
    <title>JS Function</title>
</head>
<body>
    Enter any number: <input id="num">
    <button onclick="Sum()">Sum of nth natural numbers</button>
    <p id="answer"></p>

    <script>
        function Sum() {
            var s = 0;
            var n = Number(document.getElementById("num").value);
            for (var i = 1; i <= n; i++) {
                s = s + i;
            }
            document.getElementById("answer").innerHTML = "The sum of nth natural numbers is " + s + ".";
        }
    </script>
</body>
</html>

8. Write a JavaScript code to find the multiplication of any three numbers by using a JS function.
multiply-three.html
<!DOCTYPE html>
<html>
<head>
    <title>JS</title>
</head>
<body>
    Enter the first number: <input id="num1">
    Enter the second number: <input id="num2">
    Enter the third number: <input id="num3">
    <button onclick="Mul()">Mul</button>
    <p id="result"></p>

    <script>
        function Mul() {
            var a = Number(document.getElementById("num1").value);
            var b = Number(document.getElementById("num2").value);
            var c = Number(document.getElementById("num3").value);
            var d = a * b * c;
            document.getElementById("result").innerHTML = "The multiplication of the numbers " + a + ", " + b + ", and " + c + " is " + d + ".";
        }
    </script>
</body>
</html>

📄 View / Download Full PDF Notes

If the PDF doesn’t load, click here to open it in Google Drive.

📚 Also Read: NEB Notes

Scroll to Top