JavaScript Project – Coin Toss Game Console Version

Full Stack Web Development Courses with Real-time projects Start Now!!

Program 1

//Coin Toss Game(Console Application)
"use strict"
const ps=require("prompt-sync")
const prompt=ps({sigint:true})
let choice
let compchoice,userchoice
do
{
    compchoice=Math.floor(Math.random()*2)
    console.log("---------Coin Toss Game-------------")
    console.log("\t\t 1.Head \n\t\t 2.Tail ")
    console.log("----------------------------------------")
    userchoice=parseInt(prompt("Enter Users Choice: "))
    // console.log("User choice: ",userchoice)
    // console.log("Computer choice: ",compchoice)

    if(compchoice===1)
        console.log("Its a Head....")
    else
    console.log("Its a Tail....")

    if(userchoice==1 && compchoice==1)
        console.log("Congrats You Won the toss......... !")
    else if(userchoice==2 && compchoice==0)
        console.log("Congrats You Won the toss......... !")
    else
        console.log("Oops You Lose the toss......... !")   
    
    choice=prompt("Do you 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 *