wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Seatwork #4

Total questions: 25

Worksheet time: 6hrs 1mins

Name
Class
Date
1.

What is JavaScript primarily used for?

a)

Adding interactivity to web pages

b)

Designing graphics

c)

Creating databases

d)

Managing server-side operations

2.

What does the 'var' keyword do in JavaScript?

a)

Defines a function

b)

Declares a variable

c)

Imports a library

d)

Creates a loop

3.

Which of the following is a valid way to declare a variable in JavaScript?

a)

variable myVariable = 10;

b)

myVariable := 10;

c)

set myVariable = 10;

d)

var myVariable = 10;

4.

What is the purpose of the 'alert()' function in JavaScript?

a)

To validate form inputs

b)

To create a new HTML element

c)

To log messages to the console

d)

To display a message to the user

5.

Which operator is used for multiplication in JavaScript?

a)

/

b)

x

c)

*

d)

-

6.

What will the following code output? document.write(5 + 5);

a)

Error

b)

55

c)

5 + 5

d)

10

7.

Which of the following is an "AND" operator in JavaScript?

a)

!=

b)

||

c)

and

d)

&&

8.

What does the 'confirm()' function do?

a)

Shows an alert message

b)

Prompts the user for input

c)

Displays a confirmation dialog

d)

Redirects to another page

9.

What is the correct syntax for an if statement in JavaScript?

a)

if (condition) { }

b)

if condition { }

c)

if (condition) then { }

d)

if { condition }

10.

What is the purpose of the 'break' statement in a switch case?

a)

To exit the switch block

b)

To continue to the next case

c)

To terminate the program

d)

To skip the current case

11.

What does the 'document.write()' method do?

a)

Writes value to variable

b)

Writes output to the webpage

c)

Modifies existing HTML

d)

Creates a new HTML element

12.

Which of the following is a valid comparison operator in JavaScript?

a)

=

b)

equal

c)

:

d)

==

13.

What is the purpose of the 'prompt()' function?

a)

To get user input

b)

To confirm an action

c)

To display a message

d)

To log data

14.

Which of the following is a valid way to create a comment in JavaScript?

a)

// This is a comment

b)

# This is a comment

c)

/This is a comment/

d)

/* This is a comment

15.

Based on the JavaScript in the image, what is the value of z if the first number is 1 and the second number is 2?

a)

The answer is 3

b)

12

c)

3

d)

no value

16.

What will be displayed when the following JavaScript code runs?

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

a)

Hello,

b)

undefined

c)

Hello, World!

d)

Hello,World! (no space after comma)

17.

What will be the output of the following code?

var num1 = 5;

var num2 = "5";

document.write(num1 + num2);

a)

10

b)

55

c)

5 + 5

d)

Error

18.

What will be displayed when the user enters 2?

a)

One

b)

Two

c)

Invalid

d)

Nothing

19.

What will be the output when the user enters "twenty"?

a)

Grade: D

b)

Error

c)

Nothing

d)

Grade: F

20.

What will be the value of result if the user enters 6 and 4?

var num1 = prompt("Enter first number:");

var num2 = prompt("Enter second number:");

var result = num1 * num2;

a)

64

b)

24

c)

Error

d)

Nothing

21.

How do you declare an array in JavaScript?

a)

var myArray = { };

b)

var myArray = ( );

c)

var myArray = [ ];

d)

var myArray = < >;

22.

What will fruits[1] return in the following code?

var fruits = ["Apple", "Banana", "Cherry"];

a)

"Apple"

b)

"Banana"

c)

"Cherry"

d)

Undefined

23.

What is the correct syntax for a while loop?

a)

while i < 5 { ... }

b)

while (i < 5) { ... }

c)

while i < 5: { ... }

d)

while i < 5 then { ... }

24.

What will be the output of the following code?

var count = 1;

while (count < 4) {

document.write(count + " ");

count++;

}

a)

1 2 3

b)

1 2 3 4

c)

1 1 1

d)

2 3 4

25.

What will be the output of the following code?

var sum = 0;

for (var i = 1; i <= 3; i++) {

sum += i;

}

document.write(sum);

a)

3

b)

6

c)

123

d)

0