Javascript Do While Loop

1
I think the idea there is not to repeat yourself. You're calling prompt twice. You can overcome this by declaring the variable that will be defined in the loop later. Also, make sure you terminate your statements in JS with semicolons. var secret; do { secret = prompt("What is the secret password?"); } while ( secret !== "sesame" ); document.write("You know the secret password. Welcome.");

description

Javascript do while loop

Transcript of Javascript Do While Loop

Page 1: Javascript Do While Loop

I think the idea there is not to repeat yourself. You're calling prompt twice. You can overcome this by declaring the variable that will be defined in the loop later.

Also, make sure you terminate your statements in JS with semicolons.

var secret;

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

} while ( secret !== "sesame" );

document.write("You know the secret password. Welcome.");