JSFiddle - React, Tailwind, and code Playground
JavaScript
var correctGuess = false;
var randomNumber = Math.floor(Math.random() * 6 ) + 1;
var guess = prompt('I am thinking of a number between 1 and 6. What is it?');
if (parseInt(guess) === randomNumber ) {
correctGuess = true;
} else if ( parseInt(guess) < randomNumber ){
var guessMore = prompt ('Sorry. The number is more than ' + parseInt(guess) + '. Guess again.');
if (parseInt(guessMore) === randomNumber) {
correctGuess = true;
}
} else if ( parseInt(guess) > randomNumber ) {
var guessLess = prompt ('Sorry. The number is less than ' + parseInt(guess) + '. Guess again.');
if (parseInt(guessLess) === randomNumber) {
correctGuess = true;
}
}
if ( correctGuess ) {
document.write('<p>You guessed the number!</p>');
} else {
document.write('<p>Sorry. The number was ' + randomNumber + '</p>');
}