icon picker
5. Challenge Loop

Challenge 1

Create a while loop that logs the current value of count to the console 26 times. Use the count variable to track the number of times the loop runs. Don't forget to increment count by one each time through the loop. 😀
script.js
let count = 0;

Solución

script.js
let count = 0;
while (count < 26) {
console.log(count);
count++;
}

Challenge 2

You don't always need to use a counter or specify an exact number of times that a loop must run. All you need is a condition that evaluates to false at some point so that the loop can end.

The code in script.js opens a prompt dialog that asks for a password and assigns it to the variable secret. It also displays an alert dialog. Currently, no code checks the password.

Add a do...while loop that keeps displaying the prompt dialog until the user types 'sesame'.
// Display the prompt dialogue while the value assigned to `secret` is not equal to "sesame"

let secret = prompt("What is the secret password?");

// This should run after the loop is done executing
alert("You know the secret password. Welcome!");

Solución

let secret;
do {
secret = prompt("What is the secret password?");
} while (secret !== "sesame");
alert("You know the secret password. Welcome!");
Want to print your doc?
This is not the way.
Try clicking the ⋯ next to your doc name or using a keyboard shortcut (
CtrlP
) instead.