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})
//console.log(Math.random())
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: "))
    if(compchoice==1)
        console.log("\n Its a Head... !")
    else
    console.log("\n Its a Tail... !")
    if(userchoice==compchoice)
        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.... ")

 

We work very hard to provide you quality material
Could you take 15 seconds and share your happy experience on Google

courses
Image

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 *