-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp1.js
More file actions
25 lines (21 loc) · 715 Bytes
/
app1.js
File metadata and controls
25 lines (21 loc) · 715 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
//number guess
var numberToGuess = Math.floor(Math.random() * 10) + 1;
var guesses = 0;
while (true) {
var userGuess = prompt("Guess a number between 1 and 10:");
if (userGuess == numberToGuess) {
alert(`Congratulations! You guessed the number in ${guesses + 1} attempts.`);
break;
} else if (userGuess < numberToGuess) {
alert("Too low! Try again.");
} else {
alert("Too high! Try again.");
}
guesses++;
}
//14. Collect User Input
var userInput;
do {
userInput = prompt("Enter something (type 'stop' to quit):");
console.log(userInput);
} while (userInput.toLowerCase() !== "stop"); // Using do-while loop to collect user input until user types 'stop'