<Below this line, in what way does your code behave incorrectly? Include ALL error messages.>
After Step 7 in the “Training Days” project, my output contains two null
values and I can’t figure out why. I’ve tried resetting the page, but I achieved the same results. This output occurs when I pass event
as a parameter to getEventActivities()
and getDaysToTrain()
functions. The first time I tried the exercise, I thought the following steps would eventually lead to an expected output. However, this was not the case. Following is my entire code for the project. I don’t understand! I’m also a newbie, so if there is an obvious mistake, please point it out
Thanks!
Ashley
const getAllEvents = () => {
return ['Marathon', 'Triathlon', 'Decathlon'];
};
const getRandomEvent = () => {
const allEvents = getAllEvents();
const event = allEvents[Math.floor(Math.random() * allEvents.length)];
return event;
};
const getEventActivities = event => {
const allEvents = getAllEvents();
if (!allEvents.includes(event)) {
return null;
}
let activities;
if (event === 'Marathon') {
activities = ['Running'];
return activities.join(', ');
}
if (event === 'Triathlon') {
activities = ['Running', 'Cycling', 'Swimming'];
return activities.join(', ');
}
if (event === 'Decathlon') {
activities = ['Running', 'Hurdles', 'Javelin throw', 'Discus Throw', 'Shot put', 'High Jump'];
return activities.join(', ');
}
};
const getDaysToTrain = event => {
const allEvents = getAllEvents();
if (!allEvents.includes(event)) {
return null;
}
const eventTrainingTimes = {'Marathon': 50, 'Triathlon': 100, 'Decathlon': 200 };
return eventTrainingTimes[event];
};
const getEventMessage = () => {
const myEvent = getRandomEvent();
console.log('Your event is a ' + myEvent + '. Your event activities consist of ' + getEventActivities() + '. You have ' + getDaysToTrain() + ' days to train.');
};
getEventMessage();