Advertisement
PortalPlayer

flipCoin

Jun 7th, 2020
863
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function flipCoin(whichWins) {
  2.     const flip = Math.floor(Math.random() * 4) > 2 ? "Tails" : "Heads"
  3.  
  4.     switch(whichWins) {
  5.         case "heads":
  6.             console.log(`You got ${flip}, you ${flip === "Heads" ? "win!" : "lost!"}`)
  7.             break;
  8.        
  9.         case "tails":
  10.             console.log(`You got ${flip}, you ${flip === "Tails" ? "win!" : "lost!"}`)
  11.             break;
  12.  
  13.         default:
  14.             console.log(`You got ${flip}, you ${flip === "Heads" ? "win!" : "lost!"}`)
  15.             break;
  16.     }
  17. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement