Take a look at my guess game with pure JavaScript

I tried making a guess game using JavaScript.I developed two versions of it.
v1.0
This version is just a simple version with only one trial.
It works only in the console.

Take a look

let guess = Math.floor(Math.random() * 11);
function input(num){
    if(num == guess){
        console.log("You won!");
    }else{
        console.log("You lose! try again");
    }
}
input(4);
console.log("The answer is "+ guess);

This is a really simplified version of the guess game.

v2.0
This one is a lot better than the former one as it provides the user with 5 trials.

Here are some pictures


this is the code


The game instructions would be displayed


The user would be prompted to enter their required guess


If wrong the user would have a chance to try again … This would be done for five times.

If after 5 times and the guess is not correct then you lose.

But if after entering the guess and it’s correct . You win!

The code

alert("The Guessing game \n You have 5 trials! \n You can guess from 0 - 10");
let guess = Math.floor(Math.random() * 11);
let input = prompt("Enter guess: ");
for (let countGuess = 0;countGuess < 5;countGuess++){
    if(input == guess){
        alert("You won!");
        break
    }else if(input != guess && countGuess != 4){
        input = prompt("Try again: ");
    }else{
        alert("You lose! the answer is " + guess);
    }
    console.log(countGuess);
}

Please I need your feedback

I think your project looks good.

If you wanted to expand on it, you could consider playing around with some DOM manipulation and have the users input their guesses and have it display on the screen.
You could also add a play again button so users can play multiple rounds

1 Like

I will work on it thanks :heart: