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
69 lines (57 loc) · 3.12 KB
/
Copy pathscripts.js
File metadata and controls
69 lines (57 loc) · 3.12 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
// Write your JavaScript code here.
// Remember to pay attention to page loading!
let topTracker = 0;
let leftTracker = 0;
window.addEventListener("load", function() {
let takeOffButton = document.getElementById("takeoff");
let landButton = document.getElementById("landing");
let abortMissionButton = document.getElementById("missionAbort");
takeOffButton.addEventListener("click", function() {
let input = window.confirm("Confirm that the shuttle is ready for takeoff.");
if (input) {
document.getElementById("flightStatus").innerHTML = "Shuttle in flight.";
document.getElementById("shuttleBackground").style.backgroundColor = "blue";
document.getElementById("spaceShuttleHeight").innerHTML = "10000";
}
});
landButton.addEventListener("click", function() {
window.alert("The shuttle is landing. Landing gear engaged.");
document.getElementById("flightStatus").innerHTML = "The shuttle has landed.";
document.getElementById("shuttleBackground").style.backgroundColor = "green";
document.getElementById("spaceShuttleHeight").innerHTML = "0";
});
abortMissionButton.addEventListener("click", function() {
let input = window.confirm("Confirm that you want to abort the mission.");
if (input) {
document.getElementById("flightStatus").innerHTML = "Mission aborted.";
document.getElementById("shuttleBackground").style.backgroundColor = "green";
document.getElementById("spaceShuttleHeight").innerHTML = "0";
}
});
document.getElementById("up").addEventListener("click", function() {
let myHeight = document.getElementById("spaceShuttleHeight").innerHTML;
myHeight = Number(myHeight) + 10000;
document.getElementById("spaceShuttleHeight").innerHTML = myHeight;
let rocket = document.getElementById("rocket");
topTracker = topTracker - 10;
rocket.setAttribute("style", "top: " + topTracker + "px; left: " + leftTracker + "px; position: relative;");
});
document.getElementById("down").addEventListener("click", function() {
let myHeight = document.getElementById("spaceShuttleHeight").innerHTML;
myHeight = Number(myHeight) - 10000;
document.getElementById("spaceShuttleHeight").innerHTML = myHeight;
let rocket = document.getElementById("rocket");
topTracker = topTracker + 10;
rocket.setAttribute("style", "top: " + topTracker + "px; left: " + leftTracker + "px; position: relative;");
});
document.getElementById("left").addEventListener("click", function() {
let rocket = document.getElementById("rocket");
leftTracker = leftTracker - 10;
rocket.setAttribute("style", "top: " + topTracker + "px; left: " + leftTracker + "px; position: relative;");
});
document.getElementById("right").addEventListener("click", function() {
let rocket = document.getElementById("rocket");
leftTracker = leftTracker + 10;
rocket.setAttribute("style", "top: " + topTracker + "px; left: " + leftTracker + "px; position: relative;");
});
})