forked from LaunchCodeEducation/DOM-and-Events-Studio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscripts.js
65 lines (54 loc) · 2.52 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
// 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 shuttleHeight = document.getElementById("spaceShuttleHeight");
let landing = document.getElementById("landing");
let missionAbort = document.getElementById("missionAbort");
let up = document.getElementById("up");
let down = document.getElementById("down");
let right = document.getElementById("right");
let left = document.getElementById("left");
let rocket = document.getElementById("rocket");
rocket.style.position = "relative";
takeoff.addEventListener("click", function() {
let response = window.confirm("Confirm that the shuttle is ready for takeoff.");
if (response) {
flightStatus.innerHTML = "Shuttle in flight.";
shuttleBackground.style.backgroundColor = "blue";
shuttleHeight.innerHTML = Number(shuttleHeight.innerHTML) + 10000;
}
});
landing.addEventListener("click", function() {
window.alert("The shuttle is landing. Landing gear engaged.");
flightStatus.innerHTML = "The shuttle has landed.";
shuttleBackground.style.backgroundColor = "green";
shuttleHeight.innerHTML = 0;
});
missionAbort.addEventListener("click", function(){
let response = window.confirm("Confirm that you want to abort the mission.")
if (response) {
flightStatus.innerHTML = "Mission aborted.";
shuttleBackground.style.backgroundColor = "red";
shuttleHeight.innerHTML = 0;
}
});
up.addEventListener("click", function(){
let position = rocket.style.top.slice(0, rocket.style.top.length - 2);
rocket.style.top = Number(position) - 10 + "px";
});
down.addEventListener("click", function(){
let position = rocket.style.top.slice(0, rocket.style.top.length - 2);
rocket.style.top = Number(position) + 10 + "px";
});
right.addEventListener("click", function(){
let position = rocket.style.left.slice(0, rocket.style.left.length - 2);
rocket.style.left = Number(position) + 10 + "px";
});
left.addEventListener("click", function(){
let position = rocket.style.left.slice(0, rocket.style.left.length - 2);
rocket.style.left = Number(position) - 10 + "px";
});
});