JavaScript Loops Worksheet
Questions
Question 1
What is the difference between a while loop and a for loop?
A for loop allows you to execute a code block a specific number of times. A while loop will continue to repeat as long as a boolean expression evaluates to true.
Question 2
What is an iteration?
Each time the code body is executed. The process of repeating a blockof code multiple times and controlled by a loop.
Question 3
What is the meaning of the current element in a loop?
When looping through an array, the current element is the one that is processed within the body of the loop.
Question 4
What is a 'counter variable'?
A counter variable is used to determine how many times the loop iterates.
Question 5
What does the break; statement do when used inside a loop?
It immediately terminates the loop execution and transfer control of the statement.
Coding Problems
Coding Problems - See the 'script' tag below this h3 tag. You will have to write some JavaScript code in it.
Always test your work! Check the console log to make sure there are no errors.