-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtrainingDays.js
54 lines (41 loc) · 1.34 KB
/
trainingDays.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/* this is used a few places and it is vulnerable */
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) => {
let activities = [];
const allEvents = getAllEvents();
if (!allEvents.includes(event)) {
return null;
}
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(myEvent) + '. You have ' + getDaysToTrain(myEvent) + ' days to train.');
}
getEventMessage();