Build a Fortune Teller - Build a Fortune Teller

Tell us what’s happening:

the output im getting, “7. You should generate a random number between 1 and 5, inclusive, and assign it to the variable randomNumber.
9. The randomNumber should correspond to its fortune. For example, if randomNumber is 1, the selectedFortune should be equal to fortune1 and so on.”

ive assigned the variable and called it so im confused on what i still must do. any tips before giving the solution?

Your code so far

const fortune1 = 'Your cat will look very cuddly today.';
const fortune2 = 'The weather will be nice tomorrow.';
const fortune3 = 'You will find $50 on the gound on your way to work this week.'
const fortune4 = 'Your partner will get you a gift tonight.';
const fortune5 = 'You will recieve a new job offer on friday from the career of your dreams.';
let randomNumber = Math.random() * (5 - 1) + 1;
let selectedFortune = Math.floor(randomNumber);
console.log(selectedFortune);
if (selectedFortune == 1) {
  console.log(fortune1);
}
else if (selectedFortune == 2) {
  console.log(fortune2);
}
else if (selectedFortune == 3) {
  console.log(fortune3);
}
else if (selectedFortune == 4) {
  console.log(fortune4);
}
else if (selectedFortune == 5) {
  console.log(fortune5);
}
console.log(selectedFortune)

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/137.0.0.0 Safari/537.36

Challenge Information:

Build a Fortune Teller - Build a Fortune Teller

selectedFortune seems to be equal to a random integer

yes it said i should be creating a selectedFortune variable and assigning it to the appropriate fortune but i thought i did that within the if else statements

ahhh i got it , had to change it like you said and swap the console.log to selectedFortune to equal the fortune being called in each “if” statement.

1 Like

You really need to implement precisely as the instructions say, even if the output is the same. Glad you got it!

1 Like