-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNumberGuessing_game.js
More file actions
21 lines (19 loc) · 891 Bytes
/
NumberGuessing_game.js
File metadata and controls
21 lines (19 loc) · 891 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
// Use this game on console.
while (true) {
const computerNumber = Math.floor(Math.random() * 1200) + 1;
const userInput = parseInt(prompt("Enter a number:"));
if (userInput > computerNumber) {
console.log("Your guess is too high");
console.log(`You are the winner! Your guess: ${userInput}, Computer's number: ${computerNumber}`);
} else if (userInput < computerNumber) {
console.log("Your guess is too low");
console.log(`Computer wins this game. Your guess: ${userInput}, Computer's number: ${computerNumber}`);
} else {
console.log("Both of them have the same number");
console.log(`Computer's number and your guess: ${computerNumber}, ${userInput}`);
}
const playAgain = prompt("Do you want to play again? (yes/no):");
if (playAgain.toLowerCase() !== "yes") {
break;
}
}