-
-
Save lyxal/344968f8f6e089990ad81b4f22002ac4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Prompt: In order to count to 10, you need to do the following: | |
Use a loop: | |
for (var count = 1; count < 10; count++) { console.log(count); } | |
Use a single-line if statement: | |
if (count < 10) { console.log(count); } | |
Use a while loop: | |
while (count < 10) { console.log(count); count++; } | |
Use a do-while loop: | |
do { console.log(count); count++; } while (count < 10); | |
Use a for-in loop: | |
for (var key in object) { console.log(key); } | |
Use a for-of loop: | |
for (let item of object) { console.log(item); } | |
Use a for loop: | |
for (var i = 0; i < 10; i++) { console.log(i); } | |
Use a while loop with a condition that will always be true: | |
var i = 0; while (true) { console.log(i); i++; } | |
Use the break statement: | |
for (var i = 0; i < 10; i++) { if (i == 3) { break; } console.log(i); } | |
Use the continue statement: | |
for (var i = 0; i < 10; i++) { if (i == 3) { continue; } console.log(i); } | |
Use the throw statement: | |
for (var i = 0; i < 10; i++) { if (i == 3) { throw new Error('Problem!'); } console.log(i); } | |
Use the return statement: | |
function range(start, stop, step) { for (var i = start; i < stop; i += step) { console.log(i); } return; } | |
Use the with statement: | |
var object = { firstName: 'Nicholas', lastName: 'Barry' }; with (object) { console.log(firstName); console.log(lastName); } | |
Use |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment