Web Technology
JavaScript, PHP & jQuery Fundamentals
Complete NEB Class 12 Computer Science notes on Web Technology — client-side and server-side scripting, JavaScript, PHP, jQuery — with fully solved MCQs, short answer questions, and JavaScript programming exercises.
Exercise 1: Choose the correct answer.
Select an option to view the correct answer and justification.
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.
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).
Justification: prompt() displays a dialog box asking the user to input text and returns the entered value as a string.
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.
Justification: mysqli_connect() is the current, supported PHP function used to open a connection to a MySQL database server.
Justification: In jQuery, the dollar sign ($) is an alias for the jQuery() function, e.g. $(“p”).hide() is the same as jQuery(“p”).hide().
Justification: The jQuery hide() method hides the selected elements. Options (b) and (d) are not valid jQuery methods, and (c) uses invalid syntax.
Justification: PHP’s date() function is used to format and return the current date and time based on a given format string.
Justification: External JavaScript files are linked using the <script> tag with the src attribute pointing to the file name, matching option (a) exactly.
var x = 5; var y = 2; var z = x % y;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.
Justification: The standard PHP tag opens with <?php and closes with ?>, matching option (a).
Justification: Same as Question 9 — the src attribute inside the <script> tag is the correct way to reference an external JavaScript file.
Justification: In PHP, all variables must begin with a dollar sign ($) followed by the variable name, as shown in option (d).
Justification: JavaScript is built around objects and supports object-oriented concepts, making it an object-oriented programming language.
Justification: JavaScript data types are classified into primitive types (String, Number, Boolean, etc.) and non-primitive/reference types (Object, Array, Function).
Justification: PHP is a recursive acronym officially standing for “PHP: Hypertext Pre-processor.”
Justification: concat() is used to join two or more strings together and return a new combined string, making it a String method.
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 ‘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 Scripting | Server-side Scripting |
|---|---|---|
| 1 | This code is visible to the user. | This code is not visible to the user. |
| 2 | It runs on the client computer. | It runs on the web server. |
| 3 | This code does not require frequent interaction with the server. | It needs frequent interaction with the server. |
| 4 | It does not provide high security. | It provides high security of data. |
| 5 | It reduces the load on the server. | It increases the load on the server and makes the contents dynamic. |
| 6 | Comparatively, the code execution is faster. | It is slower because it has to take the data to the server to process. |
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:
Advantages of JavaScript:
Difference between Scripting Language and Programming Language:
| S.N. | Scripting Language | Programming Language |
|---|---|---|
| 1 | Scripting languages are platform-specific. | Programming languages are platform-independent. |
| 2 | Most of the scripting languages are interpreted. | Most programming languages are compiled. |
| 3 | Scripting languages run slower than programming languages. | Programming languages run faster than scripting languages. |
| 4 | The 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)
<!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>
<!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>
<!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>
<!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>
<!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>
<!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>
<!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>
<!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.
