Question about 'Training Days' project

In the project I see that in the getTrainingDays function there are IF statements that evaluate IF event === a specific value and then sets days to a corresponding value. Where im not understanding is how does this code declare that event is equal to a perticular value anywhere? I get that we do a randevent return above, but I dont see how this sets the output of that event to a vairable called event. What am I missing here?

tl;dr: how does the getTrainingDays function know what event is if we arent assigning a value to something called event anywhere?

// The scope of `random` is too loose 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 name = 'Nala'; 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(name, event); logTime(name, days); const event2 = getRandEvent(); const days2 = getTrainingDays(event2); const name2 = 'Warren'; logEvent(name2, event2); logTime(name2, days2);
const getTrainingDays = event => {

event is the parameter of your function getTrainingDays. It will be assigned the value of whatever argument you pass into it at the time of function call.

const days2 = getTrainingDays(event2);

Here the event paramater is getting assigned whatever the value of event2 is.

1 Like

ah, yes I see now. When i run a console.log(event) inside the function block it returns the value of event which is being assigned as part of the function. Thanks friend.