Skip to content

Instantly share code, notes, and snippets.

@RaynZayd
Created October 22, 2020 09:27
Show Gist options
  • Save RaynZayd/6c0d69c3270285a036b2161cd002e236 to your computer and use it in GitHub Desktop.
Save RaynZayd/6c0d69c3270285a036b2161cd002e236 to your computer and use it in GitHub Desktop.
In this project I built a Magic Eight Ball using control flow in JavaScript. A user's able to input a question, then the program will output a random fortune.
/*In this project I built a Magic Eight Ball using control flow in JavaScript.
A user's able to input a question, then the program will output a random fortune.*/
var userName = 'Rayn';
userName ? console.log(`Hello ${userName}!`):console.log('Hello!');
let userQuestion = 'Am I beautiful';
console.log(`${userName} asked... ${userQuestion} ?`);
let randomNumber = Math.floor(Math.random()*8);
let eightBall = '';
switch(randomNumber){
case 0:
eightBall = 'It is certain';
break;
case 1:
eightBall = 'It is decidedly so';
break;
case 2:
eightBall = 'Reply hazy try again'
break;
case 3:
eightBall = 'Cannot predict now';
break;
case 4:
eightBall = 'Do not count on it';
break;
case 5:
eightBall = 'My sources say no';
break;
case 6:
eightBall = 'Outlook not so good';
break;
case 7:
eightBall = 'Signs point to yes';
break;
default:
console.log('You\'re unfortunate!');
break;
}
console.log(`The Magic Eight Ball\'s answer is... ${eightBall}`);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment