js game
js game
console.log("I'm thinking of a number between 1 and 10. Can you guess it?");
// 2. Loop until the user guesses correctly or runs out of attempts (e.g., 3 attempts)
while (guess !== secretNumber && attempts < 3) {
attempts++;
// Use prompt for browser, or simulate with console.log for Node.js
// For Node.js, you'd need a package like 'readline-sync' or a more complex setup.
// For simplicity, this example assumes a browser environment or a "manual" input for
Node.js.
// For this "short game" example, let's simulate input or assume you run it in a browser:
// Simulating input for demonstration purposes (you'd replace this with actual user input)
if (attempts === 1) guess = 5; // Example 1st guess
else if (attempts === 2) guess = 2; // Example 2nd guess
else if (attempts === 3) guess = 8; // Example 3rd guess