JavaScript program to guess a random number:

Created with Sketch.

JavaScript program to guess a random number:

let randomNumber = Math.floor(Math.random() * 100) + 1;
let guessedNumber = parseInt(prompt("Guess the number between 1 and 100:"));

while (guessedNumber !== randomNumber) {
  if (guessedNumber < randomNumber) {
    alert("Too low. Guess again.");
  } else {
    alert("Too high. Guess again.");
  }
  guessedNumber = parseInt(prompt("Guess the number between 1 and 100:"));
}

alert("You guessed it right. The number was " + randomNumber);

Leave a Reply

Your email address will not be published. Required fields are marked *