Hey guys. I’m currently working on the Training Days Javascript lesson. Below is the code that I am looking at:
// The scope of random
is too loose
const random = Math.floor(Math.random() * 3);
const getRandEvent = () => {
if (random === 0) {
return ‘Marathon’;
} else if (random === 1) {
return ‘Triathlon’;
} else if (random === 2) {
return ‘Pentathlon’;
}
};
// The scope of days
is too tight
const getTrainingDays = event => {
let days = 50;
if (event === ‘Marathon’) {
} else if (event === ‘Triathlon’) {
} else if (event === ‘Pentathlon’) {
}
My question is how did the getTrainingDays() event parameter get the value of Marathon, Tirathlon, and Penathlon? Doesn’t the return property in the getRandEvent() return those values to the caller?