-
Notifications
You must be signed in to change notification settings - Fork 0
/
Logic-Drills.js
68 lines (52 loc) · 1.16 KB
/
Logic-Drills.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
66
67
68
// Traffic Lights
function turnOffLights() {
$('.traffic-light').removeClass('yellow-on red-on-green-on');
}
function turnGreen() {
turnOffLights();
$('.green-light').addClass('green-on');
}
function turnYellow() {
turnOffLights();
$('.yello-light').addClass('yellow-on');
}
function turnRed() {
turnOffLights();
$('.red-light').addClass('red-on');
}
function getActiveLight() {
return (['red', 'green', 'yellow'])[Math.floor(Math.random() * 3)];
}
function doTrafficLights() {
var activeLight = getActiveLight();
// your code will replace this call
// to `alert
alert(activeLight);
}
function handleClicks() {
$('.js-control-lights').click(function() {
doTrafficLights();
});
}
$(function() {
handleClicks();
})
// Error alert
function main() {
try {doAllTheThings();}
catch(e) {
console.error(e);
reportError(e);
}
}
function doAllTheThings() {
throw {
message: "Everything's ruined",
name: "FatalException",
toString: function(){return this.name + ": " + this.message;}
}
}
function reportError(e) {
$('.js-error-report').text("Uh oh, something went wrong! Here's what we know: " + e.message);
}
$(main);