forked from LaunchCodeEducation/DOM-and-Events-Studio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscripts.js
68 lines (57 loc) · 2.62 KB
/
scripts.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
// Write your JavaScript code here.
// Remember to pay attention to page loading!
window.addEventListener('load', function() {
let takeoff = document.getElementById("takeoff");
let flightStatus = document.getElementById("flightStatus");
let shuttleBackground = document.getElementById("shuttleBackground");
let spaceShuttleHeight = document.getElementById("spaceShuttleHeight");
let land = document.getElementById("landing");
let abort = document.getElementById("missionAbort");
let up = document.getElementById("up");
let down = document.getElementById("down");
let left = document.getElementById("left");
let right = document.getElementById("right");
let rocket = document.getElementById("rocket");
rocket.style.position = "absolute";
rocket.style.bottom = "0px";
rocket.style.left = "0px";
takeoff.addEventListener("click", function() {
let isConfirmed = window.confirm("Confirm that the shuttle is ready for takeoff.")
if(isConfirmed) {
flightStatus.innerHTML = "Shuttle in flight";
shuttleBackground.style.backgroundColor = "blue";
spaceShuttleHeight.innerHTML = 10000;
rocket.style.bottom = parseInt(rocket.style.bottom) + 10 + "px";
}
});
land.addEventListener('click', function() {
window.alert("The shuttle is landing. Landing gear engaged.");
flightStatus.innerHTML = "The shuttle has landed."
shuttleBackground.style.backgroundColor = "green";
spaceShuttleHeight.innerHTML = 0;
rocket.style.bottom = "0px";
});
abort.addEventListener('click', function() {
let isConfirmed = window.confirm("Confirm that you want to abort the mission.");
if (isConfirmed) {
flightStatus.innerHTML = "Mission Aborted"
shuttleBackground.style.backgroundColor = "green";
spaceShuttleHeight.innerHTML = 0;
rocket.style.left = "0px";
}
});
up.addEventListener('click', function() {
rocket.style.bottom = parseInt(rocket.style.bottom) + 10 + "px";
spaceShuttleHeight.innerHTML = Number(spaceShuttleHeight.innerHTML) + 10000;
});
down.addEventListener('click', function() {
rocket.style.bottom = parseInt(rocket.style.bottom) - 10 + "px";
spaceShuttleHeight.innerHTML = Number(spaceShuttleHeight.innerHTML) - 10000;
});
left.addEventListener('click', function() {
rocket.style.left = parseInt(rocket.style.left) + 10 + "px";
});
right.addEventListener('click', function() {
rocket.style.left = parseInt(rocket.style.left) - 10 + "px";
});
});