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
59 lines (52 loc) · 2.07 KB
/
scripts.js
File metadata and controls
59 lines (52 loc) · 2.07 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
window.addEventListener("load", () => {
const status = document.getElementById("flightStatus");
const background = document.getElementById("shuttleBackground");
const height = document.getElementById("spaceShuttleHeight");
// let shuttleWidth = document.getElementById('spaceShuttleWidth');
const img = document.getElementById("rocket");
const takeOff = document.getElementById("takeoff");
takeOff.addEventListener("click", () => {
result = window.confirm("Confirm the shuttle is ready for takeoff.");
if (result) {
status.innerHTML = "Shuttle in flight.";
background.style.backgroundColor = "blue";
height.innerHTML = 10000;
}
});
const land = document.getElementById("landing");
landing.addEventListener("click", () => {
response = window.alert("The shuttle is landing. Landing gear engaged.");
if (response) {
status.innerHTML = "The shuttle has landed.";
background.style.backgroundColor = "green";
height.innerHTML = 0;
}
});
const missionAbort = this.document.getElementById("missionAbort");
missionAbort.addEventListener("click", function () {
result = window.confirm("Are you sure you want to end the mission?");
if (result) {
background.style.backgroundColor = "green";
height.innerHTML = "0";
status.innerHTML = "Mission aborted";
}
});
let shuttleWidth = document.getElementById("spaceShuttleWidth");
let right = document.getElementById("right");
right.addEventListener("click", function () {
movement = parseInt(img.style.left) + 10 + "px";
img.style.left = movement;
shuttleWidth.innerHTML = parseInt(shuttleWidth.innerHTML) + 10000;
});
let left = document.getElementById("left");
left.addEventListener("click", function () {
movement = parseInt(img.style.left) - 10 + "px";
img.style.left = movement;
});
const down = document.getElementById("down");
down.addEventListener("click", () => {
movement = parseInt(img.style.bottom) - 10 + "px";
img.style.bottom = movement;
height.innerHTML = parseInt(height) - 10000;
});
});