Friday, February 28, 2025

3. Web Technology II [Most Important Questions and Solutions]

IMPORTANT OLD QUESTION OF WEB TECHNOLOGY II

JavaScript (Client-side scripting):

2081 GIE Set A Write a JavaScript code snippet, along with HTML, that displays the multiplication table of an entered number.

Ans:

<!DOCTYPE html>

<html>

<head>

    <title>Multiplication Table</title>

</head>

<body>

    <script>

        function multiplication()

        {

         var n;

         n = parseInt(prompt("Enter a number:"));

         document.write("Multiplication Table of " + n);

         for (var i = 1; i <= 10; i++)

         {

            document.write("<br>"+ n + " × " + i + " = " + (n * i) + "<br>");

         }

        }

        multiplication();

    </script>

</body>

</html>

 

Example Output:

Enter a number: 5

Multiplication Table of 5

5 × 1 = 5
5 × 2 = 10
5 × 3 = 15
5 × 4 = 20
5 × 5 = 25
5 × 6 = 30
5 × 7 = 35
5 × 8 = 40
5 × 9 = 45
5 × 10 = 50

 

2081 Q.No. 11 Write a JavaScript function that checks if a number is even or odd and prints the result. 

Ans:

<!DOCTYPE html>

<html>

<head>

    <title>Check Even or Odd</title>

</head>

<body>

    <script>

        function checkEvenOdd()

        {

            var n;

            n = parseInt(prompt("Enter a number:"));

            if (n % 2 === 0)

            {

                document.write("The number is an Even number");

            }

            else

            {

                document.write("The number is an Odd number");

            }

        }

        checkEvenOdd();

    </script>

</body>

</html>

 

Example Output:

Enter a number: 5

The number is an Odd number

PQ1) Write a JavaScript function that checks if a number is divisible by 2 or not. 

PQ2) Write a JavaScript function that checks if a number is divisible by 13 or not. 


2081 GIE Set B/2080 GIE Set A Q.No. 11 Write a program to find the largest number among three numbers in JavaScript. [5]

Ans:

<!DOCTYPE html>

<html>

<head>

    <title>Find Largest Number</title>

</head>

<body>

    <script>

        function findLargest()

        {

            var a, b, c;

            a = parseInt(prompt("Enter first number:"));

            b = parseInt(prompt("Enter second number:"));

            c = parseInt(prompt("Enter third number:"));

            if (a >= b && a >= c)

            {

                document.write("The largest number is: " + a);

            }

            else if (b >= a && b >= c)

            {

                document.write("The largest number is: " + b);

            }  

            else

            {

                document.write("The largest number is: " + c);

            }

        }

        findLargest();

    </script>

</body>

</html>

 

Example Output:

Enter first number: 50

Enter second number: 60

Enter third number: 40

The largest number is: 60

PQ1) Write a program to find the largest number among two numbers in JavaScript.

2082 Q.No. 11 Write JavaScript code to input any three numbers and find the smallest number among them. [5]

Ans:

<!DOCTYPE html>

<html>

<head>

    <title>Find Smallest Number</title>

</head>

<body>

    <script>

        function findSmallest()

        {

            var a, b, c;

            a = parseInt(prompt("Enter first number:"));

            b = parseInt(prompt("Enter second number:"));

            c = parseInt(prompt("Enter third number:"));

            if (a <= b && a <= c)

            {

                document.write("The smallest number is: " + a);

            }

            else if (b <= a && b <= c)

            {

                document.write("The smallest number is: " + b);

             

            else

            {

                document.write("The smallest number is: " + c);

            }

        }

        findSmallest();

    </script>

</body>

</html>

 

Example Output:

Enter first number: 50

Enter second number: 60

Enter third number: 40

The smallest number is: 40


Imp Q) Write a JavaScript function that checks if a number is positive, negative or zero.

Ans:

<!DOCTYPE html>

<html>

<head>

    <title>To find positive, negative or Zero</title>

</head>

<body>

    <script>

        function checkPNO()

        {

            var n;

            n = parseInt(prompt("Enter a number:"));

            if(n > 0)

                document.write("The number is positive");

            else if(n < 0)

                document.write("The number is negative");

            else

                document.write("The number is zero");

        }

        checkPNO();

    </script>

</body>

</html>


2080 GIE Set B Q.No. 11 How do you add an event handler in JavaScript? Give an example. (What is event handling in JavaScript? Explain with example.)

Ans:

Event handling in JavaScript is the process of detecting user actions (events) on a webpage and executing specific code (a function) in response.

In JavaScript, an event handler is a function that gets executed when a specific event occurs, such as a mouse click, a key press, or a form submission. We can add event handlers using either of the following methods:

a) Inline Event Handler: Added directly inside an HTML tag using an event attribute like onclick. 

b) Using HTML DOM Property: Assign a function to the element’s event property.

b) Using addEventListener(): Attach one or more functions to an event without overwriting others.

A simple example of an inline event handler using the onclick attribute in JavaScript is as follows:

<!DOCTYPE html>

<html>

<head>

    <title>Hello World</title>

</head>

<body>

<button onclick="showMessage()">Click me</button> 

    <script>

        function showMessage()

        {

            document.write("Hello, World!");

        }

 </script>

</body>

</html> 

Explanation:

  • The showMessage() function uses document.write() to directly write the text "Hello, World!" to the page.
  • (Click me) button triggers the showMessage() function when clicked.

 

2080/2079 Set A Q.No. 11 Write a program to find the factorial of any given number using JavaScript. [5]

Ans:

<!DOCTYPE html>

<html>

<head>

    <title>Factorial of a Number</title>

</head>

<body>

    <script>

        function calculateFactorial() 

        {

            var n, fact = 1;

            n = parseInt(prompt("Enter a number:"));

            if (isNaN(n) || n < 0) 

            {

                document.write("Invalid input! Please enter a non-negative integer.");

                return;

            }

            for (var i = 1; i <= n; i++) 

            {

                fact = fact * i;

            }

            document.write("The factorial of given number is: " + fact);

        }

        calculateFactorial();

    </script>

</body>

</html>

Example Output:

Enter a number: 5

The factorial of 5 is: 120

 

2078 NEB Model/2079 GIE Set A Q.No. 11 Write a function to enter two numbers and find sum of two numbers in JavaScript. (Write a function to add any two numbers in JavaScript.)

Ans:

<!DOCTYPE html>

<html>

<head>

    <title>Sum of Two Numbers</title>

</head>

<body>

    <script>

        function calculateSum()

        {

            var a, b, s;

            a = parseInt(prompt("Enter first number:"));

            b = parseInt(prompt("Enter second number:"));

            s = a + b;

            document.write("The sum is: " + s);

        }

        calculateSum(); 

    </script>

</body>

</html>

Example Output:

Enter first number: 8

Enter second number: 7

The sum is: 15

PQ1) Write a function to enter two numbers and find difference of two numbers in JavaScript. 


2079 GIE Set B Q.No. 15 What are the uses of Java Script in web page development? [3]

Ans:

JavaScript is one of the most important client-side programming languages in web development. It plays a crucial role in creating dynamic, interactive, and user-friendly websites. Some popular uses of JavaScript in webpage development are as follows:

1.       Creating Interactive Elements: JavaScript allows developers to create interactive elements like dropdown menus, sliders, pop-ups, and form validations that improve user engagement.

2.       Asynchronous Operations (AJAX): JavaScript enables asynchronous communication with servers, allowing websites to update content without requiring a full page reload.

3.       Client-Side Scripting: JavaScript runs on the user’s browser rather than the server, reducing load time and improving website performance.

4.       Mobile and Web App Development: JavaScript is used in mobile app development through frameworks like React Native and in progressive web apps (PWAs).

5.       Security Features: JavaScript helps in real-time form validation and authentication before data is sent to the server.

 

2079 NEB Model Q.No. 11 Develop a program in JavaScript to exchange/swap the values of any two variables.  [5]

Ans:

<!DOCTYPE html>

<html>

<head>

<title> To Swap values </title>

</head>

<body>

<script> 

function swapVariables()

{

var a, b, temp;

a = parseInt(prompt("Enter value of 1st variable:"));

b = parseInt(prompt("Enter value of 2nd variable:"));

temp=a;

a=b;

b=temp;

document.write("The value of 1st variable after swap:"+a);

document.write("The value of 2nd variable after swap:"+b);

}

swapVariables();

</script>

</body>

</html>

 

Example Output:

Enter value of 1st variable: 6

Enter value of 2nd variable: 4

The value of 1st variable after swap: 4

The value of 2nd variable after swap: 6

 

HISSAN 2079 Q.No 11 Write a function to multiply two numbers in JavaScript.
Ans:

<!DOCTYPE html>

<html>

<head>

    <title>Multiplication of Two Numbers</title>

</head>

<body>

    <script>

        function calculateMultiplication()

        {

            var a, b, m;

            a = parseInt(prompt("Enter first number:"));

            b = parseInt(prompt("Enter second number:"));

            m = a * b;

            document.write("The multiplication of two numbers is: " + m);

        }

        calculateMultiplication(); 

    </script>

</body>

</html>

Example Output:

Enter first number: 8

Enter second number: 7

The multiplication of two numbers is: 56


HISSAN 2081 Q.No 11 Write a JavaScript function that takes two numbers as arguments and returns their sum.

Ans: 

<!DOCTYPE html>

<html>

<head>

    <title>Sum of Two Numbers</title>

</head>

<body>

<script>

    function sum(a, b) 

    {

        return a + b;

    }

    var result = sum(5, 7);

    document.write("The sum of 5 and 7 is: " + result);

</script>

</body>

</html>


Trinity 2081 Write the difference between server-side scripting and client-side scripting.
Ans:
Basis of Difference

Server-side Scripting

Client-side Scripting

Definition

Server-side scripting is executed on the web server before sending the result to the user’s browser.

Client-side scripting is executed in the user’s browser after the page is loaded.

Execution

It takes place on the server.

It takes place on the client’s browser.

Languages Used

Languages like PHP, Python, Ruby, ASP.NET, and Node.js are used.

Languages like JavaScript, HTML, and CSS are used for scripting and interaction.

Interaction with Database

It can directly interact with databases.

It cannot directly interact with databases and requires a server request.

Security

It is more secure because the code is hidden from the user.

It is less secure because the code is visible to the user.

Page Load Time

Pages may load slower because the server processes the script before sending it.

Pages are more responsive since scripts run locally in the browser.

Examples

Examples include login authentication, fetching data from a database, and sending emails.

Examples include form validation, animations, interactive menus, and image sliders.



St. Xavier 2080 What is operator? Explain the any five JavaScript Operator with example.

Ans: An operator is a symbol or word that indicates the type of calculation or operation to be performed on one or more operands. The different types of operators in JavaScript with examples are as follows:

1. Arithmetic Operators: Used to perform mathematical operations.

Operator

Description

Example (let a = 10, b = 5;)

Output

+

Addition

a + b

15

-

Subtraction

a – b

5

*

Multiplication

a * b

50

/

Division

a / b

2

%

Modulus (Remainder)

a % b

0

**

Exponentiation (Power)

a ** b

100000

2. Assignment Operators: Used to assign values to variables.

Operator

Description

Example (let a = 10;)

Equivalent To

=

Assign value

a = 10

a = 10

+=

Add & Assign

a += 5

a = a + 5

-=

Subtract & Assign

a -= 5

a = a – 5

*=

Multiply & Assign

a *= 5

a = a * 5

/=

Divide & Assign

a /= 5

a = a / 5

%=

Modulus & Assign

a %= 5

a = a % 5

3. Comparison Operators: Used to compare values (returns true or false).

Operator

Description

Example (let a = 10, b = 5;)

Output

==

Equal (loose comparison)

a == "10"

True

===

Identical (strict comparison)

a === "10"

False

!=

Not equal

a != b

True

!==

Not identical

a !== "10"

True

Greater than

a > b

True

Less than

a < b

False

>=

Greater than or equal

a >= 10

True

<=

Less than or equal

a <= 5

False

4. Logical Operators: Used to perform logical operations.

Operator

Description

Example (let x = true, y = false;)

Output

&&

Logical AND

x && y

False

||

Logical OR

X || y

true

!

Logical NOT

!x

false

5. Increment & Decrement Operators: Used to increase or decrease values.

Operator

Description

Example (let a = 10;)

Output

++a

Pre-increment

++a

11

a++

Post-increment

a++

10 (then 11)

--a

Pre-decrement

--a

9

a--

Post-decrement

a--

10 (then 9)


HISSAN 2080 SET M Q.No 11 What is a function in JS? Write a function in JavaScript to find simple interest and display the result using alert method on clicking button.

Ans: In JavaScript (JS), a function is a block of code that performs a specific task and can be reused whenever needed. A function is defined using the function keyword followed by a name, parentheses () for parameters, and curly braces {} for the code block.

<!DOCTYPE html>

<html>

<head>

    <title>Simple Interest Calculator</title>

</head>

<body>

    <button onclick="calculateSI()">Calculate Simple Interest</button>

    <script>

        function calculateSI()

        {

            var p, r, t, si;

            p = parseFloat(prompt("Enter the principal amount:"));

            r = parseFloat(prompt("Enter the rate of interest in percent:"));

            t = parseFloat(prompt("Enter the time in years:"));

            si = (p * r * t) / 100;

            alert("The Simple Interest (SI) is: " + si);

        }

    </script>

</body>

</html>


CFAN MODEL 2081 Write a JavaScript program to check whether the given number is prime

or composite.

Ans:

<!DOCTYPE html>

<html>

<head>

    <title>Find Prime or Composite</title>

</head>

<body>

<script>

    function checkPrimeComposite()

    {

        var n, c = 0;

        n = parseInt(prompt("Enter a number:"));

        if (n <= 1)

        {

            document.write("The number is neither Prime nor Composite");

            return;

        }

        for (var i = 1; i <= n; i++) 

            {

            if (n % i === 0) {

                c++;

            }

        }

        if (c === 2) 

        {

            document.write("The number is Prime");

        } else {

            document.write("The number is Composite");

        }

    }

    checkPrimeComposite();

</script>

</body>

</html>


Asmita Set Q.No 11 OR Write a JavaScript to print the largest and smallest numbers among 10 elements of an array.    [5]

Ans:

<!DOCTYPE html>

<html>

<head>

  <title>Largest and Smallest in Array</title>

</head>

<body>

  <script>

    var numbers = [];

    // Get 10 numbers from the user

    for (var i = 0; i < 10; i++)

    {

      numbers[i] = parseInt(prompt("Enter number " + (i + 1) + ":"));

    }

    // Initialize largest and smallest with the first element

    var largest = numbers[0];

    var smallest = numbers[0];

    // Loop through the array to find largest and smallest

    for (var i = 1; i < 10; i++)

    {

      if (numbers[i] > largest)  

      {

        largest = numbers[i];

      }

      if (numbers[i] < smallest)

      {

        smallest = numbers[i];

      }

    }

    // Display the results after the loop finishes

    document.write("Largest number: " + largest);

    document.write("Smallest number: " + smallest);

  </script>

</body>

</html>

 


PHP (Server-side scripting):

2081 Q.No. 11 OR What is the purpose of the mysqli_connect() function in PHP? Describe its usage and parameters. [2+3]

Ans:

The mysqli_connect() function in PHP is essential for establishing a connection between a PHP script and a MySQL database server. This connection is the foundation for any PHP application that needs to interact with a MySQL database, allowing it to perform operations like querying, inserting, updating, and deleting data.

Purpose, usage, and parameters of mysqli_connect() function in PHP are as follows:

Purpose:

Ø To create a link between a PHP script and a MySQL database server.

Ø To enable the PHP script to send and receive data from the MySQL database.

Usage:

An example to demonstrate usage of mysqli_connect() function in PHP is as follows:

<?php

// Step 1: Database configuration

$servername = "localhost";

$username = "root";

$password = "";

$database = "studentDB";

 

//Step2: Database connection

$con = new mysqli($servername, $username, $password, $database);

 

// Step 3: Check connection 

if ($con->connect_error) {

    die("Connection failed: " . $con->connect_error);

} else {

    echo "Connected successfully!";

}

?>

Parameters:

$servername – The hostname or IP of the database server (e.g., "localhost" or "127.0.0.1").

$username – The MySQL database username (e.g., "root").

$password – The MySQL database password (e.g., "" for empty or "your_password").

$database – The name of the database (e.g., "studentDB").

$port(optional) – The port number for the database connection (default: 3306).

$socket(optional) – The socket or named pipe used for the connection. 


2080 GIE Set A Q.No. 11 OR How do you connect a MySQL (Client-Side scripting) database with PHP (Server-Side Scripting)? Explain with an example. [5]

2080 GIE Set B Q.No. 11 OR Explain the database connection PHP function for MySQL. [5]

2079 GIE Set A Q.No. 11 OR Explain the database connection method in PHP.    [5]

2079 GIE Set B Q.No. 15 How do you connect the PHP and My SQL database? Explain with connection class.   [5]

2079 NEB Model Q.No. 11 OR How can you connect a database with PHP? Demonstrate with an example.   [5]

Ans:

Database connectivity refers to the process of connecting a server-side script (like PHP) to a database (like MySQL) to store, retrieve, update, and delete data. The new mysqli() or mysqli_connect() function in PHP is essential for establishing a connection between a PHP script and a MySQL database server. Syntax for Database Connection is as follows:

$con = new mysqli($servername, $username, $password, $database);

OR

$con = mysqli_connect($servername, $username, $password, $database);

We can connect a MySQL (Client-Side scripting) database with PHP (Server-Side Scripting) by following these steps as shown in example below:

<?php

// Step 1: Database configuration

$servername = "localhost";

$username = "root";

$password = "";

$database = "studentDB";

 

//Step2: Database connection

$con = new mysqli($servername, $username, $password, $database);

 

// Step 3: Check connection 

if ($con->connect_error) {

    die("Connection failed: " . $con->connect_error);

} else {

    echo "Connected successfully!";

}

?>

Explanation:

  1. Create a Connection – Uses the new mysqli() object-oriented method to establish a connection.
  2. Check Connection – Uses $con->connect_error to check if there was a connection error.
  3. Error Handling – If the connection fails, it stops execution with die() and outputs the error.
  4. Success Message – If the connection is successful, it prints "Connected successfully!".

 

2080 Q.No. 11 Define syntax for database connectivity. Write a server-side scripting code to insert data into the table student having fields (first name, last name, mark and email). Assume that server name= “localhost”, username=”root”, password=” “, database name=”student DB”.

2081 PABSON Q.No. 11 Write a PHP program to insert data in a database.

Ans:  

Syntax for Database Connectivity:

$con = new mysqli($servername, $username, $password, $database);

OR

$con = mysqli_connect($servername, $username, $password, $database);

 

A server-side scripting code to insert data into the table student having fields (first name, last name, mark and email) is as follows:

<?php

// Step 1: Database configuration

$servername = "localhost";

$username = "root";

$password = "";

$database = "studentDB";

 

//Step2: Database connection

$con = new mysqli($servername, $username, $password, $database);

 

// Step 3: Check connection

if ($con->connect_error)

{

    die("Connection failed: " . $con->connect_error);

} else {

    echo "Connected successfully!";

}

 

// Step 4: Prepare the SQL statement for insertion

$sql = "INSERT INTO student (first_name, last_name, mark, email)

             VALUES ('Madhav', 'Sapkota', 30, 'madhav@gmail.com')";

 

// Step 5: Execute the query and check if data is inserted

if ($con->query($sql) === TRUE)

{

    echo "Data inserted successfully";

} else {

    echo "Error: " . $sql . "<br>" . $con->error;

}

// Step 5: Close connection

$con->close();

?>

 

2081 GIE Set A Q.No. 11 OR Develop a PHP code to add a record like (601, Raju, M, 12-06-2002, Kathmandu) in the table named info_stud having structure (reg_no integer, name character 25, gender character 1, dob character 10, address character 25) of the database named "School".

Ans:

A PHP code to insert the record (601, Raju, M, 12-06-2002, Kathmandu) into the table info_stud in the database "School" is as follows:

<?php

// Step 1: Database configuration

$servername = "localhost";

$username = "root";

$password = "";

$database = "School";

 

// Step 2: Database connection

$con = new mysqli($servername, $username, $password, $database);

 

// Step 3: Check connection

if ($con->connect_error)

{

    die("Connection failed: " . $con->connect_error);

} else {

    echo "Connected successfully!";

}

 

// Step 4: Prepare the SQL statement for insertion

$sql = "INSERT INTO info_stud (reg_no, name, gender, dob, address)

             VALUES (601, 'Raju', 'M', '12-06-2002', 'Kathmandu')";

 

// Step 5: Execute the query and check if data is inserted

if ($con->query($sql) === TRUE)

{

    echo "Record added successfully!";

} else {

    echo "Error: " . $sql . "<br>" . $con->error;

}

 

// Step 6: Close connection

$con->close();

?>

 

2079 Set A Q.No. 11 OR How do you fetch data from a database in PHP and display it in form? Describe. [5]

Ans:

To fetch data from a database in PHP and display it in form, follow these steps as shown in example below:

<!DOCTYPE html>

<html>

<head>

    <title>Fetch Data and Display in Form</title>

</head>

<body>

<?php

//Step 1: Database configuration

$servername = "localhost";

$username = "root";

$password = "";

$database = "test_db";

 

// Step 2: Database connection

$con = new mysqli($servername, $username, $password, $database);

 

// Step 3: Check connection

if ($con->connect_error) {

    die("Connection failed: " . $con->connect_error);

}

 

// Step 4: Fetch data when ID is provided (Example: user with ID=1)

$id = 1;

$sql = "SELECT * FROM users WHERE id = $id";

$result = $con->query($sql);

 

//Step 5: Check if data exists

if ($result->num_rows > 0) {

    $row = $result->fetch_assoc();

} else {

    echo "No record found!";

    exit();

}

?>

<!--Step 6: Display Data in Form -->

<form method="post">

    Name: <input type="text" name="name" value="<?php echo $row['name']; ?>">

    Age: <input type="number" name="age" value="<?php echo $row['age']; ?>">

    <input type="submit" name="update" value="Update">

</form>

</body>

</html>

 

2081 GIE Set A Q.No. 11 OR Write a PHP program to swap two numbers.   [5]

Ans:

<!DOCTYPE html>

<html>

<head>

    <title>Swap Two Numbers</title>

</head>

<body>

<form method="post">

  Enter First Number: <input type="number" name="a" required>

  Enter Second Number: <input type="number" name="b" required>

  <input type="submit" name="swap" value="Swap">

</form>

<?php

if(isset($_POST['swap']))

{

    $a = $_POST['a'];

    $b = $_POST['b'];

    $temp = $a;

    $a = $b;

    $b = $temp;

    echo "The value of 1st variable after swap:" . $a;

    echo "The value of 2nd variable after swap:" . $b;

}

?>

</body>

</html>


Write a PHP program to find sum of two numbers.

Ans:

<!DOCTYPE html>

<html>

<head>

    <title>Sum of Two Numbers</title>

</head>

<body>

<form method="post">

  Enter First Number: <input type="number" name="a" required>

  Enter Second Number: <input type="number" name="b" required>

  <input type="submit" name="sum" value="Calculate Sum">

</form>

<?php

if(isset($_POST['sum']))

{

    $a = $_POST['a'];

    $b = $_POST['b'];

    $sum = $a + $b;

    echo "The sum of the two numbers is:" . $sum;

}

?>

</body>

</html>  

 

Write a PHP program to display the largest among three numbers.

Ans:

<!DOCTYPE html>

<html>

<head>

    <title>Largest Among Three Numbers</title>

</head>

<body>

<form method="post">

  Enter First Number: <input type="number" name="a" required>

  Enter Second Number: <input type="number" name="b" required>

  Enter Third Number: <input type="number" name="c" required>

  <input type="submit" name="largest" value="Find Largest">

</form>

<?php

if(isset($_POST['largest']))

{

    $a = $_POST['a'];

    $b = $_POST['b'];

    $c = $_POST['c'];

    if ($a > $b && $a > $c)

    {

        echo "The largest number is:" . $a;

    }

    elseif ($b > $c)

    {

        echo "The largest number is:" . $b;

    }

    else

    {

        echo "The largest number is:" . $c;

    }

}

?>

</body>

</html>


Write a PHP program to check whether the given number is even or odd.

Ans:

<!DOCTYPE html>

<html>

<head>

    <title>Even or Odd</title>

</head>

<body>

<form method="post">

  Enter a Number: <input type="number" name="num" required>

  <input type="submit" name="check" value="Check">

</form>

<?php

if(isset($_POST['check']))

{

    $num = $_POST['num'];

    if ($num % 2 == 0)

    {

        echo "The number is even";

    }

    else

    {

        echo "The number is odd";

    }

}

?>

</body>

</html>


MULTIPLE CHOICE QUESTIONS:

1. 2081 GIE Set A What is a scripting language that runs for the browser of the user's Computer?

A) Object-oriented programming

B) Server-side scripting language

C) Client-side scripting Language

D) Structure programming Language

2. 2081 GIE Set A Predict the correct output of the following PHP code.

                       <?php $ x=30; $y = 30;

                       if ($x>$y) echo "CDC, Nepal.";

                       else echo "NEB, Nepal."; ?>

A) 30 is not greater than 30.                                                              

B) CDC, Nepal                          

C) NEB, Nepal.                                         

D) No output.

3. 2080 GIE Set A Analyse the expected output of the provided in JavaScript snippet.

  <script> var p=120, Q=O; document. Write (P/Q); </script>

A) Garbage value                          B) 0                           C) 120                               D) Infinity is pointed

4. 2081 GIE Set B What type of language is PHP?

a) Client-side scripting

b) Server-side scripting

c) User-side scripting

d) Machine level

5. 2081 GIE Set B Which JavaScript method is used to write HTML output?

a) console.log()

b) document.output()

c) document.write()

d) document.writeHTML()

6. 2081 GIE Set B Which sign is used to declare variables in PHP?

a) @           b) *            c) ^                 d) $

7. 2081 What is the correct syntax for a 'for-loop' in JavaScript?
a. for (var i = 0; i < 5; i++)
b. for (i = 0; i < 5; i++)
c. for (var i < 5; i++)
d. for (var i = 5; i++)

8. 2081 Which PHP function is commonly used to execute SQL queries on a database connection established using MySQL extension?
a. mysqli_query()
b. pdo_query()
c. mysql_connect()
d. pgsql_query()

9. 2080 GIE Set A 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. println

10. 2080 GIE Set B Which JavaScript function is used to take text input?
a. alert()
b. prompt()
c. confirm()
d. console.log()

11. 2080 GIE Set B 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()

12. 2080 Which of the given signs is used as a shortcut for jQuery?
a. The * sign
b. The & sign
c. The $ sign
d. The @ sign

13. 2080 Which jQuery method is used to hide selected elements?
a. hide()        b. hide(on)      c. invisible()       d. display(none)

14. 2079 GIE Set A 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

16. 2079 GIE Set B What would be the value of "z" in the given JavaScript code?

var x = 5;

var y = 2;

var z = x % y;

a. 0                         b. 2                        c. 1                      d. 2.5

17. 2079 GIE Set B Which is the correct opening and closing tag for PHP scripts?
a. { }          b. <?php ?>          c. ( )                  d. <??>

18. 2079 Set A/2079 GIE Set A What is the correct syntax for referring to an external JavaScript script?
a. <script src="myscript.js"></script>
b. <script href="myscript.js"></script>
c. <js href="myscript.js"></js>
d. <js src="myscript.js"></js>

19. 2079 Set A Which of the following is the correct way of defining a variable in PHP?
a. $variable name = value;
b. $variable_name = value;
c. $variable.name = value;
d. $variable name as value;

20. 2079 NEB Model Which of the following keywords are used to declare a variable in

JavaScript?

A) int or var

B) float or let

C) var or let

D) char or var

21. 2079 NEB Model Which of the following commands is executed in PHP to concatenate the variables $x with $y?

A) $x + $y

B) $x=$y

C) concat ($x,$y)

D) $x.$y

22. ……. Extracts a section of a string and returns a new string

a. set() method      b. slice() method      c. split() method   d. None

20. JavaScript is ...
a. Procedural-oriented language
b. Object-oriented programming language
c. Firmware
d. None of the above

23. Data types in JavaScript are ...
a. Primary and secondary
b. Primitive and non-primitive
c. Local and universal
d. None of the above

24. PHP stands for ...
a. Hypertext Pre-processor
b. Program hyper processor
c. Process hyper program
d. None of the above

25. concat() is ...
a. Integer method
b. String method
c. Image method
d. None of the above

26. ... is an identifier whose value may change during the execution of the program.
a. Constant             b. Function      c. Variable     d. None of the above

27. What is a scripting language that runs for the browser of the user's Computer?

A) Object-oriented programming

B) Server-side scripting language

C) Client-side scripting Language

D) Structure programming Language

28. Predict output

<?

$fruits=array("mango","apple","pear","peach");

$fruits = array_reverse($fruits);

echo($fruits[2]);

?>
a. mango          b. peach        c. pear        d. apple

29. Which of the following is the correct syntax to display "Stay Safe" in an alert box using JavaScript?

a) alert-box("Stay Safe");

b) confirm("Stay Safe");

c) msgbox("Stay safe");

d) alert("Stay Safe");

30. Which of the following is a ternary operator in JS?

a) -         b) ?:         c) +              d) :

31. Which of the following can’t be done with client-side JavaScript?

a) Validating a form

b) Sending a form’s content by email

c) Storing the form’s contents to a database file on the server

d) None of the above

32. Which of the following language is not web scripting language?

 a. HTML           b. CSS              c. JavaScript                d. C Language

33. Which of the following statement is not true?

    a. HTML is standard language for development webpages

    b. HTML helps to embed text, graphics, audio, video and animation on  
         webpage

    c. HTML is also used to store database in websites

    d. HTML also defines a link to traverse from one page to another

34. An example of client-side scripting language is ....

 a. PHP               b. JSP             c. ASP           d. JavaScript

35. JavaScript was originally developed by ......

 a. Google      b. Microsoft      c. Sun microsystem      d. Netscape

36. What are the basic three types of data in JavaScript?

  a. Numbers, Strings and Boolean

  b. Numbers Strings and Bytes

  c. Integer, Character and Boolean

  d. Numbers, Strings and Array

37. Greater than equal to >= is an example of

 a. Assignement    b. Comparaison     c. Logical     d. Conditional

38. Which of the following statement is not a type of looping statement?

 a. do while         b. for         c. switch case           d. while

39. Which of the following is not an example of object?

  a. Array       b. String        c. Image         d. Number

40. Which of the following statement is not true?

  a. PHP is open-source scripting language

  b. PHP is client site scripting language

  c. PHP can be integrated with database like MYSQL, Oracle, Sybase and  
      MS SQL Server

  d. PHP syntax is same as C language

41. What are the two method of form access?

  a. get/post       b. give/take      c. input/output           d. get/set

44. Which Program Copies The Databases From One Server To Another?

 a. Mysqlcopydb      b. Mysqldbcopy     c. Mysqlflushdb   d. Mysqldbflush

45. Which among the following have the maximum bytes?

  a. varchar     b. char     c. Both varchar and char      d. Text Type

46. The "father" Of MYSQL......

  a. Bill Joy     b. Michael Widenius     c. Bill Gates      d. Stephanie Wall

47. Read all MCQ from Asmita Textbook

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home