JavaScript Project – Guess Random Number Game Console Version
Full Stack 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

