-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtrainingDays.js
61 lines (51 loc) · 1.49 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
55
56
57
58
59
60
61
const name = 'Ubaid';
const name2 = 'Jorge';
const name3 = 'Jonathan';
//This function gets us a random event
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';
}
};
//This function takes in a parameter (event, which is assigned getRandEvent) and determining on what that value is returns a certain amount of days
const getTrainingDays = event => {
let days;
if (event === 'Marathon') {
days = 50;
} else if (event === 'Triathlon') {
days = 100;
} else if (event === 'Pentathlon') {
days = 200;
}
return days;
};
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`);
};
//Event is assigned a random event
const event = getRandEvent();
//Then days is assigned a random training day since event is passed in
const days = getTrainingDays(event);
//Function Caller 1
logEvent(name,event);
logTime(name,days);
console.log(' ')//We only added this line to seperate our outputs on the console
const event2 = getRandEvent();
const days2 = getTrainingDays(event2);
//Function caller 2
logEvent(name2, event2);
logTime(name2, days2);
console.log(' ')
const event3 = getRandEvent();
const days3 = getTrainingDays(event3);
//function caller 3
logEvent(name3, event3);
logTime(name3, days3);