Hi guys, I´m scrating my head here… The output field for event2 correctly changes the event at random, but the number of days to train clones event1. I can´t work out why ???
const name = ‘Nala’;
const getRandEvent = () => {
const random = Math.floor(Math.random() * 3);
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;
if (event === ‘Marathon’) {
days = 50;
} else if (event === ‘Triathlon’) {
days = 100;
} else if (event === ‘Pentathlon’) {
days = 200;
}
return days;
};
// The scope of name
is too tight
const logEvent = (name, event) => {
console.log(${name}'s event is: ${event}
);
};
const logTime = (name, event) => {
console.log(${name}'s time to train is: ${days} days
);
};
const event = getRandEvent();
const days = getTrainingDays(event);
// Define a name
variable. Use it as an argument after updating logEvent and logTime
logEvent(name, event);
logTime(name, days);
//end of nalas selection
const event2 = getRandEvent();
const days2 = getTrainingDays(event2);
const name2 = ‘Warren’;
logEvent(name2, event2);
logTime(name2, days2);
console.log(event2)
console.log(days2)
OUTPUT ( The event for event2 changes at random correctly, but the number of days clones thefirst event,
Nala’s event is: Pentathlon
Nala’s time to train is: 200 days
Warren’s event is: Triathlon
Warren’s time to train is: 200 days