JavaScript Loops Worksheet
Questions
Question 1
What is the difference between a while loop and a for loop?
While loops work as long as the boolean condition is true. For loops, on the other hands, use a counter variable
that works in conjunction with its boolean.
Question 2
What is an iteration?
It refers to a single loop done by one of these code lines. Likewise, looping is also known as iterating.
Question 3
What is the meaning of the current element in a loop?
It is whatever element is featured in the current iteration of a loop. For example, if a loop statement is going through a
list with the letters X, Y, Z, and A and is currently on the 2nd iteration, then Y is the current element.
Question 4
What is a 'counter variable'?
The counter variable is the main component in for loops, as it's what keeps track of how long the loop must run.
The counter variable itself will almost always be represented by either "x" or "i".
Question 5
What does the break; statement do when used inside a loop?
It ends the loop prematurely. This is useful for when you only want to run the loop for a certain point or use a limit other than a counter variable.
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.