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
68 lines (58 loc) · 2.38 KB
/
scripts.js
File metadata and controls
68 lines (58 loc) · 2.38 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
window.addEventListener("load", function() {
let imgObj = document.getElementById('rocket');
imgObj.style.position= 'absolute';
imgObj.style.left = '0px';
imgObj.style.bottom = '0px';
let status = document.getElementById('flightStatus');
let shuttleHeight = document.getElementById('spaceShuttleHeight');
let bg = document.getElementById('shuttleBackground');
let right = this.document.getElementById('right');
right.addEventListener("click", function () {
movement = parseInt(imgObj.style.left) + 10 + 'px';
imgObj.style.left = movement;
});
let left = this.document.getElementById('left');
left.addEventListener("click", function () {
movement = parseInt(imgObj.style.left) - 10 +'px';
imgObj.style.left = movement;
});
let down = this.document.getElementById('down');
down.addEventListener("click", function () {
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 () {
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';
shuttleHeight.innerHTML = '10000';
status.innerHTML = "Shuttle in flight";
}
});
let land = this.document.getElementById('land');
land.addEventListener("click", function () {
bg.style.backgroundColor = 'green';
window.alert('The shuttle is landing. Landing gear engaged.');
shuttleHeight.innerHTML = '0';
status.innerHTML = "Shuttle landed";
imgObj.style.bottom = '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';
status.innerHTML = "Mission aborted";
imgObj.style.bottom = '0px';
}
});
});