N. Achyut javascript Number Guessing Game in JavaScript – Free JavaScript Project

Number Guessing Game in JavaScript – Free JavaScript Project

NUMBER GUESSING GAME IN JAVASCRIPT

Before Starting with this project you need to learn about basic HTML and css code to make it beautiful and moreover JavaScript.

The game is to guess a random number generating by computer.

Different Javascript Functions are used in this project, The main javascript code is given below and for the full code you can see in github

// let guessNo = "2";
let guessNo = (Math.random())*10; // generating random number and multiply it by 10 
guessNo = Math.round(guessNo); // rounding up the decimal ramdom no 
let body = document.querySelector("body");
while(true){
    let num = Number(prompt("Guess number between 0 to 10"));
    if(num && num ==guessNo){
        body.style.backgroundColor = "yellow"
        body.style.color = "red"
        body.innerHTML = "<h1>YOU WIN</h1>"
        break;
    }
}

Related Post