In this project I built a Magic Eight Ball game using switch and case statemtnts.
The user will be able to input a question and then output a random fortune.
let userName ='';userName ==='Jane'?console.log('Hello, Jane!') :console.log('Hello!');let userQuestion ='What is this game?';console.log(`${userName}, ${userQuestion}`);let randomNumber =Math.floor(Math.random() *7);let eightBall ='';switch (randomNumber) {case0: eightBall = randomNumber;console.log('It is certain');break;case1: eightball = randomNumber;console.log('It is decidedly so');breakcase2: eightBall = randomNumber;console.log('Reply hazy try again');break;case3: eightBall = randomNumber;console.log('Cannot predict now');break;case4: eightBall = randomNumber;console.log('Do not count on it');break;case5: eightBall = randomNumber;console.log('My sources say no');break;case6: eightBall = randomNumber;console.log('Outlook not so good');break;case7: eightBall = randomNumber;console.log('Signs point to yes');break;console.log(eightBall);}// Output: Hello!// , What is this game?// My sources say no
In the above example everytime we run the code it results in a different result.