NEW
Font size
WorksheetsSeatwork #4
Total questions: 25
Worksheet time: 6hrs 1mins
What is JavaScript primarily used for?
Adding interactivity to web pages
Designing graphics
Creating databases
Managing server-side operations
What does the 'var' keyword do in JavaScript?
Defines a function
Declares a variable
Imports a library
Creates a loop
Which of the following is a valid way to declare a variable in JavaScript?
variable myVariable = 10;
myVariable := 10;
set myVariable = 10;
var myVariable = 10;
What is the purpose of the 'alert()' function in JavaScript?
To validate form inputs
To create a new HTML element
To log messages to the console
To display a message to the user
Which operator is used for multiplication in JavaScript?
/
x
*
-
What will the following code output? document.write(5 + 5);
Error
55
5 + 5
10
Which of the following is an "AND" operator in JavaScript?
!=
||
and
&&
What does the 'confirm()' function do?
Shows an alert message
Prompts the user for input
Displays a confirmation dialog
Redirects to another page
What is the correct syntax for an if statement in JavaScript?
if (condition) { }
if condition { }
if (condition) then { }
if { condition }
What is the purpose of the 'break' statement in a switch case?
To exit the switch block
To continue to the next case
To terminate the program
To skip the current case
What does the 'document.write()' method do?
Writes value to variable
Writes output to the webpage
Modifies existing HTML
Creates a new HTML element
Which of the following is a valid comparison operator in JavaScript?
=
equal
:
==
What is the purpose of the 'prompt()' function?
To get user input
To confirm an action
To display a message
To log data
Which of the following is a valid way to create a comment in JavaScript?
// This is a comment
# This is a comment
/This is a comment/
/* This is a comment
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?
The answer is 3
12
3
no value
What will be displayed when the following JavaScript code runs?
document.write("Hello, " + "World!");
Hello,
undefined
Hello, World!
Hello,World! (no space after comma)
What will be the output of the following code?
var num1 = 5;
var num2 = "5";
document.write(num1 + num2);
10
55
5 + 5
Error
What will be displayed when the user enters 2?
One
Two
Invalid
Nothing
What will be the output when the user enters "twenty"?
Grade: D
Error
Nothing
Grade: F
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;
64
24
Error
Nothing
How do you declare an array in JavaScript?
var myArray = { };
var myArray = ( );
var myArray = [ ];
var myArray = < >;
What will fruits[1] return in the following code?
var fruits = ["Apple", "Banana", "Cherry"];
"Apple"
"Banana"
"Cherry"
Undefined
What is the correct syntax for a while loop?
while i < 5 { ... }
while (i < 5) { ... }
while i < 5: { ... }
while i < 5 then { ... }
What will be the output of the following code?
var count = 1;
while (count < 4) {
document.write(count + " ");
count++;
}
1 2 3
1 2 3 4
1 1 1
2 3 4
What will be the output of the following code?
var sum = 0;
for (var i = 1; i <= 3; i++) {
sum += i;
}
document.write(sum);
3
6
123
0
