// 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;
};
const name = ‘Nala’;
// The scope of name is too tight
const logEvent = (name, event) => {
console.log(${name}'s event is: ${event});
};
const logTime = (name, days) => {
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(event);
logTime(days);
/>
The above is my code. It is from the scoping exercise on JavaScript. In one part of the exercise, it asks us to " Pass name as the first argument to logEvent() and logTime() ." However, when I do this, the following is output:
Why does it change the name to Triatholon, Marathon, or Pentathlon and the event and days become undefined? If I remove the parameters, the code runs fine, but the exercise asks you to add the parameters, so I know it’s supposed to work.