1
2
3
4
5
6
7
8
9
10
To practice on your own, or to check code you believe shouldn't have been scored as incorrect, go to CodePen.
0,1,2,3,4,5,6,7,8,9
0
0
0
0
A for…of loop is a good way to loop over an array, string, or other _______. | iterable | iterable | |
The first keyword inside the parentheses of a for…of loop can be let or ____. | const | const | |
The name of the array is arr. Fill in the blank. | for (const elem __________) { | of arr | ofarr |
The name of the string is str. The variable is char. Code the first line of the for…of loop using const. | for (const char of str) { | for\(constcharofstr\){ | |
Below is an array. Code the first line of a for…of loop that iterates through the array. Make up the name of the variable. Use const. | let arr = [12, 24, 36]; | for (const elem of arr) { | for\(const[a-z_$][a-zA-Z0-9_$]*ofarr\){ |
Code a complete for…of loop that displays, in turn, each element of an array in the console. Make up the names of the array and the variable. Use const. | for (const elem of arr) { console.log(elem); } |
for\(const([a-z_$][a-zA-Z0-9_$]*)of[a-z_$][a-zA-Z0-9_$]*\){[\r\n]console\.log\(\1\);[\r\n]} | |
Code a complete for…of loop that displays, in turn, each element of an integer array in the console. If a particular integer turns up, skip to the next element. Make up everything. Use const. | for (const elem of arr) { if (elem === 0) { continue; } console.log(elem); } |
for\(const([a-z_$][a-zA-Z0-9_$]*)of[a-z_$][a-zA-Z0-9_$]*\){[\r\n]if\(\1===(0|-?[1-9][\d]*)\){[\r\n]continue;[\r\n]}[\r\n]console\.log\(\1\);[\r\n]} | |
Code a complete for…of loop that displays, in turn, each character of a string. If a particular character turns up, end the loop. Make up everything. Use const. | for (const elem of arr) { if (elem === "z") { break; } console.log(elem); } |
for\(const([a-z_$][a-zA-Z0-9_$]*)of[a-z_$][a-zA-Z0-9_$]*\){[\r\n]if\(\1===•.*•\){[\r\n]break;[\r\n]}[\r\n]console\.log\(\1\);[\r\n]} | |
|
|||
|