-
Notifications
You must be signed in to change notification settings - Fork 0
/
Playing w: JavaScript.js
65 lines (54 loc) · 1.62 KB
/
Playing w: JavaScript.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
62
63
64
65
const logVisibleLightWaves = () => {
const lightWaves = 'Moonlight';
//if you delete line 4 then line 7 will not display anything in the console. The {} limit the scope of the
//variable to inside the {} line 7 diplays the function that takes place within the {}...
console.log(lightWaves);
}
logVisibleLightWaves();
//line 9 will not work becuase the function is declared within the scope of the {}. It is block scope...
console.log(lightWaves);
//Training Days exercise
// The scope of `random` is too loose
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';
}
};
// The scope of `days` is too tight
const getTrainingDays = event => {
let days;
if (event === 'Marathon') {
days = 50;
} else if (event === 'Triathlon') {
days = 100;
} else if (event === 'Pentathlon') {
days = 200;
}
return days;
};
// The scope of `name` is too tight
const name = 'Nala';
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`);
};
const event = getRandEvent();
const days = getTrainingDays(event);
// Define a `name` variable. Use it as an argument after updating logEvent and logTime
logEvent(name,event);
logTime(name,days);
const event2 = getRandEvent();
const days2 = getTrainingDays(event2);
const name2 = 'Warren';
logEvent(name2,event2);
logTime(name2,days2);
console.log(words.some((word) => {
return word.length < 6;
}));