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
124 lines (108 loc) · 4.89 KB
/
scripts.js
File metadata and controls
124 lines (108 loc) · 4.89 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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
// Write your JavaScript code here.
// Remember to pay attention to page loading!
//const input = require('readline-sync');
let takeoffButton = null;
let landingButton = null;
let missionAbortButton = null;
let upButton = null;
let rightButton = null;
let downButton = null;
let leftButton = null;
let rocket = null;
function init() {
takeoffButton = document.getElementById('takeoff');
landingButton = document.getElementById('landing');
missionAbortButton = document.getElementById('missionAbort');
upButton = document.getElementById('up');
downButton = document.getElementById('down');
rightButton = document.getElementById('right');
leftButton = document.getElementById('left');
rocket = document.getElementById('rocket');
rocket.style.position = 'absolute';
rocket.style.left = '0px';
rocket.style.bottom = '0px';
takeoffButton.addEventListener("click", function(event) {
let confirmation = confirm("Confirm that the shuttle is ready for takeoff.");
if (confirmation) {
document.getElementById('flightStatus').innerHTML = 'Shuttle in flight.';
document.getElementById('shuttleBackground').style.backgroundColor = 'blue';
document.getElementById('spaceShuttleHeight').innerHTML = '10000';
}
});
landingButton.addEventListener('click', function(event) {
if (document.getElementById('flightStatus').innerHTML === 'Shuttle in flight.') {
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';
rocket.style.left = '0px';
rocket.style.bottom = '0px';
} else {
alert("Already grounded.");
}
});
missionAbortButton.addEventListener('click', function(event) {
if (document.getElementById('flightStatus').innerHTML === 'Shuttle in flight.') {
let confirmation = confirm("Confirm that you want to abort the mission.");
if (confirmation) {
document.getElementById('flightStatus').innerHTML = 'Mission aborted.';
document.getElementById('shuttleBackground').style.backgroundColor = 'green';
document.getElementById('spaceShuttleHeight').innerHTML = '0';
rocket.style.left = '0px';
rocket.style.bottom = '0px';
}
} else {
alert("There's no mission going on right now, crazy!");
}
});
rightButton.addEventListener('click', function() {
if (document.getElementById('flightStatus').innerHTML === 'Shuttle in flight.') {
if (parseInt(rocket.style.left) < 550) {
let movement = parseInt(rocket.style.left) + 10 + 'px';
rocket.style.left = movement;
}
} else {
alert("Liftoff has not been initiated.");
}
});
leftButton.addEventListener('click', function() {
if (document.getElementById('flightStatus').innerHTML === 'Shuttle in flight.') {
if (parseInt(rocket.style.left) > -20) {
let movement = parseInt(rocket.style.left) - 10 + 'px';
rocket.style.left = movement;
}
} else {
alert("Liftoff has not been initiated.");
}
});
upButton.addEventListener('click', function() {
if (document.getElementById('flightStatus').innerHTML === 'Shuttle in flight.') {
if (parseInt(rocket.style.bottom) < 250) {
let movement = parseInt(rocket.style.bottom) + 10 + 'px';
rocket.style.bottom = movement;
let height = parseInt(document.getElementById('spaceShuttleHeight').innerHTML) + 10000;
document.getElementById('spaceShuttleHeight').innerHTML = height.toString();
}
} else {
alert("Liftoff has not been initiated.");
}
});
downButton.addEventListener('click', function() {
if (document.getElementById('flightStatus').innerHTML === 'Shuttle in flight.') {
if (parseInt(rocket.style.bottom) > 0) {
let movement = parseInt(rocket.style.bottom) - 10 + 'px';
rocket.style.bottom = movement;
let height = parseInt(document.getElementById('spaceShuttleHeight').innerHTML) - 10000;
document.getElementById('spaceShuttleHeight').innerHTML = height.toString();
}
} else {
alert("Liftoff has not been initiated.");
}
});
rocket.addEventListener('click', function() {
rocket.style.left = '0px';
rocket.style.bottom = '0px';
document.getElementById('spaceShuttleHeight').innerHTML = '10000';
});
}
window.onload = init;