NEW
Font size
WorksheetsQuiz # 5 (Second Quarter)
Total questions: 20
Worksheet time: 8mins
What is the main purpose of a for loop in JavaScript?
To check conditions only
To repeat a block of code multiple times
To store multiple values in a one variable
To stop the execution of a program
It decides how long the loop will run in a for loop.
Initialization
Declaration
Condition
Update
This is where you set up the loop's starting point. You typically declare and assign a value to a counter variable.
Initialization
Condition
Update
Execution
A condition usually runs with this operators.
Arithmetic Operators
Assignment Operators
Logical Operators
Comparison Operators
This part of the expression modifies the counter variable after each loop iteration. It add or deduct value.
Update
Condition
Initialization
Declaration
Which refers to a collection of data, or an ordered list of values, where each value can be of any data type.
For Loop
Expression
Array
Variable
Which is a numerical value that identifies the position of a specific element within the array.
Drawer
Array
Index
Value
Which statement is best for exiting a loop prematurely?
continue
break
stop
return
Which operator increases a variable after using its current value?
++i
--i
i--
i++
Which operator decreases a variable by 2 after using its current value?
i += 2;
i -= 2;
i = 2 + 1;
i = i + i;
Which control flow structure is best for handling multiple distinct options?
if statement
for loop
if else statement
switch statement
Which loop is best for iterating over array elements?
if
for
while
do.. while
LOOK AT THE IMAGE
If a programmer wants to print the colors in reverse:
Which loop setup is correct?
for (let i = 0; i < colors.length; i++)
for (let i = colors.length; i > 0; i--)
for (let i = colors.length - 1; i >= 0; i--)
for (let i = 1; i <= colors.length; i++)
LOOK AT THE IMAGE
Which change will make this loop stop after printing numbers 1 to 10?
Change < to <=
Change i++ to i--
Change starting value to 0
Remove the condition
A school uses a loop to record 30 students’ attendance.
If a student arrives between 8:00–8:14 AM, the system marks “Late.”
What control flow structure best fits this logic?
for loop only
if-else if inside a for loop
A single if statement
A while loop
LOOK AT THE IMAGE
What is the output of this code?
Apple+Banana+Mango
Mango Banana Apple
AppleBananaMango
Apple Banana Mango
Why does JavaScript array indexing start at 0 instead of 1?
To confuse beginners, since we learned to count starting with 1 not 0.
To save memory and space on our storage devices.
Because of how memory addresses work and efficiency in computing
Because it’s required by HTML, and that is how it was made by the developers
LOOK AT THE IMAGE
In a traffic light simulation using arrays and loops:
Which loop statement would correctly cycle through each light once?
for (let i = 1; i < 3; i++)
for (let i = 0; i <= 3; i++)
for (let i = 1; i <= lights.length; i++)
for (let i = 0; i < lights.length; i++)
If brushing your teeth daily is like a loop, what represents the loop condition?
The act of brushing your teeth
The toothbrush that you used and change after a month
The moment you stop brushing when your teeth are clean
The toothpaste used depend on the brand
LOOK AT THE IMAGE
What will happen when this code runs?
It will print 1 to 5 correctly
It will not print anything
It will cause an infinite loop
It will throw a syntax error
