JavaScript Project – Guess Random Number Game Console Version

Free Web development courses with real-time projects Start Now!!

Program 1

//Guess Random Number Game(Console Application)
"use strict"
const ps=require("prompt-sync")
const prompt=ps({sigint:true})
let choice
do
{
    let compchoice,userchoice
    let count=5
    let i=0
    compchoice=Math.floor(Math.random()*100)
    console.log("-----------Guess Random Number Game----------------")
    console.log("Enter your guess(0-99) and if you guess in 5 attempts You are Winner !")

    while(1)
    {    
        userchoice=parseInt(prompt("Enter Your Guess Number:(0 to 99): "))
        i++
        count--
        if(userchoice>compchoice)
            console.log("Wrong... your number is grater....! Now " + count + " chance left")
        else if(userchoice<compchoice)
        console.log("Wrong... your number is less....! Now " + count + " chance left")
        else if(userchoice==compchoice)
        {
            console.log("Wow Congrats You won the game in " + i + " chance")
            break
        }
        if(count==0)    
        {
            console.log("Oops you lose the game... chance over ..!")
            console.log("Correct Number is : " + compchoice)
            break
        }
    }  
    choice=prompt("Want to play more...!(yes/no): ").toLowerCase() 
}while(choice=="yes")   
    console.log("Thanks for playing Bye Bye ..!")

 

If you are Happy with DataFlair, do not forget to make us happy with your positive feedback on Google

courses

DataFlair Team

DataFlair Team provides high-impact content on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. We make complex concepts easy to grasp, helping learners of all levels succeed in their tech careers.

Leave a Reply

Your email address will not be published. Required fields are marked *