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
87 lines (80 loc) · 3.36 KB
/
scripts.js
File metadata and controls
87 lines (80 loc) · 3.36 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
76
77
78
79
80
81
82
83
84
85
86
87
// Write your JavaScript code here.
// Remember to pay attention to page loading!
window.addEventListener("load", function() {
let imgObj = this.document.getElementById('rocket');
imgObj.style.position= 'absolute';
imgObj.style.left= '0px';
imgObj.style.bottom= '0px'; //imgObj was spelled wrong
let status = document.getElementById('flightStatus'); //element was spelled elements
let shuttleHeight = document.getElementById('spaceShuttleHeight');
let shuttleWidth = document.getElementById('spaceShuttleWidth');
let bg = document.getElementById('shuttleBackground');
let right = this.document.getElementById('right');
right.addEventListener("click", function () {
if (shuttleWidth.innerHTML != "510000") {
movement = parseInt(imgObj.style.left) + 10 + 'px';
imgObj.style.left = movement;
shuttleWidth.innerHTML = parseInt(shuttleWidth.innerHTML) + 10000;
}
else{
console.log('right move')
}
});
let left = this.document.getElementById('left');
left.addEventListener("click", function () {
if (shuttleWidth.innerHTML != "-20000") {
movement = parseInt(imgObj.style.left) - 10 + 'px';
imgObj.style.left = movement;
shuttleWidth.innerHTML = parseInt(shuttleWidth.innerHTML) - 10000;
}
});
let down = this.document.getElementById('down');
down.addEventListener("click", function () {
if (shuttleHeight.innerHTML != "0") {
movement = parseInt(imgObj.style.bottom) - 10 + 'px';
imgObj.style.bottom = movement;
shuttleHeight.innerHTML = parseInt(shuttleHeight.innerHTML) - 10000;
}
});
let up = this.document.getElementById('up');
up.addEventListener("click", function () {
if (shuttleHeight.innerHTML != "250000") {
movement = parseInt(imgObj.style.bottom) + 10 + 'px';
imgObj.style.bottom = movement;
shuttleHeight.innerHTML = parseInt(shuttleHeight.innerHTML) + 10000;
}
});
let takeoff = this.document.getElementById('takeoff');
takeoff.addEventListener("click", function () {
result = window.confirm("Are you sure the shuttle is ready for takeoff?");
if (result) {
bg.style.backgroundColor = 'blue';
movement = parseInt(imgObj.style.bottom) + 10 + 'px';
imgObj.style.bottom = movement;
shuttleHeight.innerHTML = '10000';
status.innerHTML = "Shuttle in flight";
}
});
let landing = this.document.getElementById('landing');
landing.addEventListener("click", function () {
bg.style.backgroundColor = 'green';
window.alert("The shuttle is landing. Landing gear engaged.");
shuttleHeight.innerHTML = '0';
shuttleWidth.innerHTML = '0';
status.innerHTML = "Shuttle landed";
imgObj.style.bottom = '0px';
imgObj.style.left = '0px';
});
let missionAbort = this.document.getElementById('missionAbort');
missionAbort.addEventListener("click", function () {
result = window.confirm("Are you sure you want to end the mission?");
if (result) {
bg.style.backgroundColor = 'green';
shuttleHeight.innerHTML = '0';
shuttleWidth.innerHTML = '0';
status.innerHTML = "Mission aborted";
imgObj.style.bottom = '0px';
imgObj.style.left = '0px';
}
});
});