Build a Fortune Teller - Build a Fortune Teller

Tell us what’s happening:

Having an issue with the coding of the conditional statements - commented them out as that code causes all the other tests to fail.
I’ve tried a couple different versions of what I thought would be appropriate…, I think I’m not understanding exactly how to address the assignment of the different fortunes.

Your code so far

const fortune1 = "Your cat will look very cuddly today.";
console.log(fortune1);
const fortune2 = "The weather will be nice tomorrow.";
console.log(fortune2);
const fortune3 = "Be cautious of your new neighbors.";
console.log(fortune3);
const fortune4 = "You will find a new hobby soon.";
console.log(fortune4);
const fortune5 = "It would be wise to avoid the color red today.";
console.log(fortune5);

const randomNum = Math.random();
console.log(randomNum);

const randomNumber = Math.floor(Math.random()*5) + 1;
console.log(randomNumber);

const selectedFortune = console.log(randomNumber);

/* if (randomNumber === 1) {
  selectedFortune = console.log(fortune1);
}
else if ( randomNumber === 2) {
  selectedFortune = console.log(fortune2);
}
else if (randomNumber === 3) {
  selectedFortune = console.log(fortune3);
}
else if (randomNumber === 4) {
  selectedFortune = console.log(fortune4);
}
else if (randomNumber === 5) {
  selectedFortune = 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/139.0.0.0 Safari/537.36

Challenge Information:

Build a Fortune Teller - Build a Fortune Teller
https://www.freecodecamp.org/learn/full-stack-developer/lab-fortune-teller/build-a-fortune-teller

What does this line do?

sets the definition for selectedFortune - so then the commented code is redundant with the console.log of randomNumber ?

Be more specific. How did you declare your variable?

ahhh, I made it a constant, which would make the first value immutable?

1 Like