-
-
Save codecademydev/628763884f5577c063dcbebc5809936b to your computer and use it in GitHub Desktop.
Codecademy export
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let userName = 'Joan'; | |
//greeting | |
userName ? console.log(`Hello, ${userName}!`) : console.log('Hello!'); | |
//Question | |
let userQuestion = 'Will I get a good job?'; | |
//Prints question | |
userName ? console.log(`${userName} asks: ${userQuestion}`) : console.log(`The question is: ${userQuestion}`); | |
//Get random number from 0 to 7. | |
let randomNumber = Math.floor(Math.random() * 8); | |
console.log(randomNumber); | |
//create variable for the eightBall answer. | |
let eightBall = ''; | |
/*switch-statement control flow to get eightball answer based on random number. | |
switch (randomNumber) { | |
case randomNumber=0: | |
eightBall='You will be happy forever.'; | |
break; | |
case randomNumber=1: | |
eightBall='You already know the answer.'; | |
break; | |
case randomNumber=2: | |
eightBall='Your life will change today.'; | |
break; | |
case randomNumber=3: | |
eightBall='Try again.'; | |
break; | |
case randomNumber=4: | |
eightBall='Absolutely!'; | |
break; | |
case randomNumber=5: | |
eightBall='Your deepest fears will come true.'; | |
break; | |
case randomNumber=6: | |
eightBall='It will all work out in your favor.'; | |
break; | |
case randomNumber=7: | |
eightBall='You should give up.'; | |
break; | |
}*/ | |
//control flow to get eightBall answer | |
if (randomNumber=0) { | |
eightBall='You will be happy forever.'; | |
} else if (randomNumber=1) { | |
eightBall='Blah'; | |
} else if (randomNumber=2) { | |
eightBall='Your life will change today.'; | |
} else if (randomNumber=3) { | |
eightBall='Try again.'; | |
} else if (randomNumber=4) { | |
eightBall='Absolutely!'; | |
} else if (randomNumber=5) { | |
eightBall='Your deepest fears will come true.'; | |
} else if (randomNumber=6) { | |
eightBall='It will all work out in your favor.'; | |
} else if (randomNumber=7) { | |
eightBall='You should give up.'; | |
} | |
//print eightBall answer | |
console.log(`The eight ball answered: ${eightBall}`); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment