Thisis the course project I am referring to. I am not struggling to complete the project, as a matter of fact I fixed the whole thing in a couple of minutes. I did it partially by accident by misreading the first step, and doing something different then I guess I was supposed to. My question is what is the point of this lesson, and all of the seemingly unnecessary steps? Maybe I’m missing some big piece of information regarding js, and even though what I did works great on codeacademy but in practice not so much. I know scope is an integral part of a good working program and that it can get really hairy at times if you’re not careful and don’t understand it, so I would like to avoid bad habits and learning things incorrectly. So you can see what I did I will past my code below:
// The scope of random
is too loose
name = ‘Nala’
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 = () => {
let days = event;
if (event === ‘Marathon’) {
return days = 50;
} else if (event === ‘Triathlon’) {
return days = 100;
} else if (event === ‘Pentathlon’) {
return days = 200;
}
};
// The scope of name
is too tight
const logEvent = () => {
console.log(${name}'s event is: ${event}
);
};
const logTime = 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);