forked from LaunchCodeEducation/DOM-and-Events-Studio
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscripts.js
More file actions
75 lines (57 loc) · 2.31 KB
/
scripts.js
File metadata and controls
75 lines (57 loc) · 2.31 KB
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
69
70
71
72
73
74
75
window.addEventListener("load", function(){
let statusNode = document.getElementById("flightStatus");
let bgNode = document.getElementById("shuttleBackground");
let heightDisplayNode = document.getElementById("spaceShuttleHeight");
let rocketNode = document.getElementById("rocket");
// direction is either "up" or "down"
function moveVertical(direction) {
let displayHeightChange = 10000;
let imgHeightChange = 10;
if (direction === 'down') {
displayHeightChange = -displayHeightChange;
imgHeightChange = -imgHeightChange;
}
let currentHeight = Number(heightDisplayNode.innerHTML);
currentHeight += displayHeightChange;
heightDisplayNode.innerHTML = currentHeight;
let currentImgHeight = parseInt(rocketNode.style.bottom);
rocketNode.style.bottom = (currentImgHeight + imgHeightChange) + "px";
}
// TODO 1: create a moveHorizontal function that takes "left" or "right" as a param
let takeoffBtn = document.getElementById("takeoff");
takeoffBtn.addEventListener("click", function() {
let confirmed = window.confirm("Confirm that the shuttle is ready for takeoff");
if (confirmed) {
statusNode.innerHTML = "Shuttle in flight.";
bgNode.style.backgroundColor = "blue";
moveVertical("up");
}
});
let landBtn = document.getElementById("landing");
landBtn.addEventListener("click", function(){
window.alert("The shuttle is landing. Landing gear engaged.");
statusNode.innerHTML = "The shuttle has landed.";
bgNode.style.backgroundColor = "green";
heightDisplayNode.innerHTML = "0";
rocketNode.style.bottom = "0px";
});
let abortBtn = document.getElementById("missionAbort");
abortBtn.addEventListener("click", function(){
let confirmed = window.confirm("Confirm that you want to abort the mission.");
if (confirmed) {
statusNode.innerHTML = "Mission aborted.";
bgNode.style.backgroundColor = "green";
rocketNode.style.bottom = "0px";
heightDisplayNode.innerHTML = "0";
}
});
let upBtn = document.getElementById("up");
upBtn.addEventListener("click", function() {
moveVertical("up");
});
let downBtn = document.getElementById("down");
downBtn.addEventListener("click", function(){
moveVertical("down");
});
// TODO 2: get the left button, and call moveHorizontal
});