Assignment 022

Do...While Loops

Another useful programming structure is the do...while loop. Unlike the while loop, the do...while loop tests the condition at the end of the code. This means the code will always run at least once.

You guessed my number! <script language="Javascript" type="text/javascript">
//declare the number variable
var number
//set value of number variable
number = 75;

//declare the guess variable
var guess;

//create a prompt loop
//keep looping until the user guesses the correct number
do
{
guess = window.prompt("Guess a number from 1 to 100", "");
}
while (guess != number)

document.write("You guessed my number!");
</script>