Console is printing correctly the correct random numbers and fortune numbers , But I can’t get throught this step9.
9. The randomNumber should correspond to its fortune. For example, if randomNumber is 1, the selectedFortune should be equal to fortune1 and so on
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 maxNum = 5 ;
const minNum = 1 ;
const randomNumber = Math.floor(Math.random() * (maxNum - minNum + 1) + (minNum));
let selectedFortune = randomNumber;
if (randomNumber == 1){console.log(fortune1)} else if (randomNumber == 2){console.log(fortune2)} else if (randomNumber == 3){console.log(fortune3)}else if (randomNumber == 4){console.log(fortune4)} else if (randomNumber == 5){console.log(fortune5)};
console.log(selectedFortune)
Your browser information:
User Agent is: Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/141.0.0.0 Mobile Safari/537.36
follow the direction* in 9 using the right syntax of if statement. Review conditional statements using operands, their meaning and when to use them. you’re almost there. compare step 9 with 10 direction and you’ll realize what you did wrong. Hint! don’t do what they don’t ask you . I had one variable declaration wrong to pass, it took me 2 days to realize my mistake. give it some time.
My issue with this task is that step 8. of the assignment makes me assume that I should define the following (since the step also checkmarked after I did this)
let selectedFortune = randomNumber;
8. You should have a selectedFortune variable that is assigned a value based on the value of randomNumber.
Thats why I went on doing this:
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);
}
It did what it was supposed to, but steps 9. and 10. didn’t pass. The explanation above doesn’t really help my confusion. Can you explain to me again like I’m a child what I am doing wrong? Thanks alot!
you should create your own topic when you need help
If you have a question about a specific challenge as it relates to your written code for that challenge and need some help, click the Get Help > Ask for Help button located on the challenge.
The Ask for Help button will create a new topic with all code you have written and include a link to the challenge also. You will still be able to ask any questions in the post before submitting it to the forum.