Build a Fortune Teller - Build a Fortune Teller

Tell us what’s happening:

My code doesn’t work for some and i can’t pass the test.

Your code so far

const fortune1 = “Your cat will look very cuddly today.”;

const fortune2 = “The weather will be nice tomorrow.”;

const fortune3 = “Be cautious of your new neighbours.”;

const fortune4 = “You will find a new hobby soon.”;

const fortune5 = “It would be wise to avoid the color red today.”;

const randomNumber = Math.random() * (5 - 1) + 1;

let selectedFortune;

if (randomNumber == 1){
selectedFortune = fortune1;
}

else if (randomNumber == 2){
selectedFortune = fortune2;
}

else if (randomNumber == 3){
selectedFortune = fortune3;
}

else if (randomNumber == 4){
selectedFortune = fortune4;
}

else if (randomNumber == 5){
selectedFortune = fortune5;
}
console.log(selectedFortune);

const fortune1 = "Your cat will look very cuddly today.";

const fortune2 = "The weather will be nice tomorrow.";

const fortune3 = "Be cautious of your new neighbours.";

const fortune4 = "You will find a new hobby soon.";

const fortune5 = "It would be wise to avoid the color red today.";

const randomNumber = Math.random() * (5 - 1) + 1;



let selectedFortune;

if (randomNumber == 1){
  selectedFortune = fortune1;
}

else if (randomNumber == 2){
  selectedFortune = fortune2;
}

else if (randomNumber == 3){
  selectedFortune = fortune3;
}

else if (randomNumber == 4){
  selectedFortune = fortune4;
}

else if (randomNumber == 5){
  selectedFortune = fortune5;
}
console.log(selectedFortune);

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:137.0) Gecko/20100101 Firefox/137.0

Challenge Information:

Build a Fortune Teller - Build a Fortune Teller

Hi there,

You’re almost there, just a small fix!

You’re using this to get the random number:

const randomNumber = Math.random() * (5 - 1) + 1;

But this gives you a decimal between 1 and 5 (not an integer), so none of the if conditions (like randomNumber == 1) match!

Fix: Use Math.floor() or Math.ceil()

This will give you an integer between 1 and 5.

1 Like

Thank you very much for the help . i really appreciate it your solution worked.

1 Like