Tell us what’s happening:
Test case #7 does not recognize the randomNumber.
Is there something I am doing wrong?
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 neighbors.";
const fortune4 = "You will find a new hobby soon.";
const fortune5 = "It would be wise to avoid the color red today.";
const min = 1;
const max = 5;
const randomNumber = Math.floor(Math.random() * (max - min) + min);
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 {
selectedFortune = 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/151.0.0.0 Safari/537.36
Challenge Information:
Build a Fortune Teller - Build a Fortune Teller
GitHub Link: freeCodeCamp/curriculum/challenges/english/blocks/lab-fortune-teller/66c06d618d075c7f7f1b890a.md at main · freeCodeCamp/freeCodeCamp · GitHub
7. You should generate a random number between 1 and 5, inclusive, and assign it to the variable randomNumber.
Teller
3
Hi @neahpanilag
To help you debug, add the following console log:
console.log(Math.floor(Math.random() * (max - min) + min), Math.floor(Math.random() * (max - min) + min), Math.floor(Math.random() * (max - min) + min), Math.floor(Math.random() * (max - min) + min), Math.floor(Math.random() * (max - min) + min), Math.floor(Math.random() * (max - min) + min), Math.floor(Math.random() * (max - min) + min),Math.floor(Math.random() * (max - min) + min), Math.floor(Math.random() * (max - min) + min), Math.floor(Math.random() * (max - min) + min), Math.floor(Math.random() * (max - min) + min), Math.floor(Math.random() * (max - min) + min), Math.floor(Math.random() * (max - min) + min));
Happy coding
Another strict evaluation yet it seems.
Math.floor(Math.random() * 5) + 1; fixes it but has literally the same effect as my code.
const min = 1;
const max = 5;
const randomNumber = Math.floor(Math.random() * (max - min) + min);
Both vars are defined.
Teller
6
What can you say about the list of numbers generated by the console log?