Trainingdays has the same event

This results in the same amount of days even though the events are different. Any ideas of what I’ve missed? Thanks in advance.

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; }; 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); const event2 = getRandEvent(); const days2 = getTrainingDays(event); const name2 = 'Warren'; logEvent(name, event); logTime(name, days); logEvent(name2, event2); logTime(name2, days2);

You have
const days2 = getTrainingDays(event);
for Warren
but event is for Nala,
(you already used event earlier to get days for Nala).

So the event should be event2 (for days2 )
if you want a possibly different event for Warren than for Nala.

2 Likes