Build a Fortune Teller - Build a Fortune Teller

Tell us what’s happening:

Hello everyone, I have a question about Math.random().

I completed the lab using the function
let randomNumber = Math.floor(Math.random() * 5) + 1;

But when I define the code as follows:

const minNumber = 1;
const maxNumber = 2;
randomNumber = Math.floor(Math.random() * (maxNumber - minNumber + 1) - minNumber;

it is not possible to complete the lab. What is wrong with the code?

I based it on (HELP/LOST)Generate Random Whole Numbers within a Range .

Your code so far

let fortune1 =  "Your cat will look very cuddly today.";
let fortune2 = "The weather will be nice tomorrow.";
let fortune3 = "Be cautious of your new neighbours.";
let fortune4 = "You'll find a new hobby soon.";
let fortune5 = "It would be wise to avoid the color red today,";


const minNumber = 1;
const maxNumber = 5;
let randomNumber = Math.floor(Math.random() * (maxNumber - minNumber + 1)) - minNumber;

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);

Challenge Information:

Build a Fortune Teller - Build a Fortune Teller

what is this subtraction doing?

Thanks for the quick reply. I was just about to write that I noticed it’s addition and not subtraction.

That means: randomNumber = Math.floor(Math.random() * (maxNumber - minNumber + 1) + minNumber;

is the same as

let randomNumber = Math.floor(Math.random() * 5) + 1;

First forum post, immediately unnecessary ^^

1 Like