Using While loop to check user input : while « Statement « JavaScript Tutorial






<html>
<head>
<title>Using While loop to check user input</title>
<script>
var correct = "AA";
var guess = "";
while (guess != correct){
  guess = prompt ("Question?", "");
  if (guess == correct){
    alert ("Correct");
  } else {
    alert ("that's not it...");
  }
}

</script>
</head>
<body>
</body>
</html>








3.6.while
3.6.1.while loop
3.6.2.Use integer variable to control the while loop
3.6.3.Check the loop counter for while loop
3.6.4.Use while loop to output all elements in an array
3.6.5.Use Do while loop to reverse a string
3.6.6.Nesting If statement to a while statement
3.6.7.Using While loop to check user input