I’ve been studying up on my javascript lately. In one of the tutorials I was doing it had us build a magic eight ball program.
I thought that was cool. So I added some spice to it to hard code in the question, “Am I going to act a fool tonight?”
Now I have a script I can run when I feel like partying and need some insight on just how dicey the night is going to get.
function myFunction() {
let userName = 'Hogan'
userName ? console.log(`Hello, ${userName}`) : console.log('Hello!')
let userQuestion = 'Am I going to act a fool tonight?'
console.log(`${userName}, you 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 = 'Signs point to yes';
break;
}
console.log(eightBall);
}
If you like this content, subscribe to our email list in order to get notified about new post.