I’ve worked through this project a couple times and can’t seem to get past this error…
/home/ccuser/workspace/learn-javascript_scope-training-days/trainingDays.js:38
return activities.join(', ');
^TypeError: Cannot read property ‘join’ of undefined
at getEventActivities (/home/ccuser/workspace/learn-javascript_scope-training-days/trainingDays.js:38:22)
at getEventMessage (/home/ccuser/workspace/learn-javascript_scope-training-days/trainingDays.js:56:84)
at Object. (/home/ccuser/workspace/learn-javascript_scope-training-days/trainingDays.js:59:1)
at Module._compile (module.js:571:32)
at Object.Module._extensions…js (module.js:580:10)
at Module.load (module.js:488:32)
at tryModuleLoad (module.js:447:12)
at Function.Module._load (module.js:439:3)
at Module.runMain (module.js:605:10)
at run (bootstrap_node.js:427:7)
Here’s my code…
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’) {
const activities = [‘Running’];
}
if (event === ‘Triathlon’) {
const activities = [‘Running’, ‘Cycling’, ‘Swimming’];
}
if (event === ‘Decathlon’) {
const 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];
};getRandomEvent();
const getEventMessage = () => {
const myEvent = getRandomEvent();console.log('Your event is a ’ + myEvent + '. Your event activities consist of ’ + getEventActivities(myEvent) + ‘. You have ’ + getDaysToTrain(myEvent) + ’ days to train.’);
}getEventMessage();