Take a look at my guess game with pure JavaScript

I tried making a guess game using JavaScript.I developed two versions of it.
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!");
        console.log("You lose! try again");
console.log("The answer is "+ guess);

This is a really simplified version of the guess game.

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!");
    }else if(input != guess && countGuess != 4){
        input = prompt("Try again: ");
        alert("You lose! the answer is " + guess);

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:

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.