Skip to content

Commit 433a235

Browse files
committed
studio commit with takeoff and landing completely done
1 parent 5c544d0 commit 433a235

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed

dom-and-events/studio/scripts.js

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,62 @@
11
// Write your JavaScript code here.
22
// Remember to pay attention to page loading!
3+
window.addEventListener("load", () =>{
4+
const takeOffButton = document.getElementById('takeoff');
5+
const landButton = document.getElementById('landing');
6+
const abortButton = document.getElementById('missionAbort');
7+
const upButton = document.getElementById('up');
8+
const downButton = document.getElementById('down');
9+
const rightButton = document.getElementById('right');
10+
const leftButton = document.getElementById('left');
11+
12+
const flightStatus = document.getElementById('flightStatus');
13+
const shuttleBackground = document.getElementById('shuttleBackground');
14+
const spaceShuttleHeight = document.getElementById('spaceShuttleHeight');
15+
const rocket = document.getElementById('rocket');
16+
17+
takeOffButton.addEventListener('click', function(){
18+
if(window.confirm('Confirm that the shuttle is ready for takeoff.')){
19+
flightStatus.textContent = 'Shuttle in flight.';
20+
shuttleBackground.style.backgroundColor = 'blue';
21+
spaceShuttleHeight.textContent = parseInt(spaceShuttleHeight.textContent) + 1000;
22+
}
23+
})
24+
landButton.addEventListener('click',function(){
25+
window.alert('The shuttle is landing. Landing gear engaged.');
26+
flightStatus.textContent = 'The shuttle has landed.';
27+
shuttleBackground.style.backgroundColor = 'green';
28+
spaceShuttleHeight.textContent = 0;
29+
rocket.style.bottom = '0px';
30+
})
31+
abortButton.addEventListener('click', function(){
32+
if (window.confirm('Confirm that you want to abort the mission.')){
33+
flightStatus.textContent = 'Mission aborted.';
34+
shuttleBackground.style.backgroundColor = 'green';
35+
spaceShuttleHeight.textContent = 0;
36+
rocket.style.bottom = '0px';
37+
38+
}
39+
})
40+
upButton.addEventListener('click', function() {
41+
let currentBottom = parseInt(rocket.style.bottom) || 0;
42+
rocket.style.bottom = (currentBottom + 10) + 'px';
43+
spaceShuttleHeight.textContent = parseInt(spaceShuttleHeight.textContent) + 10000;
44+
})
45+
downButton.addEventListener('click', function() {
46+
let currentBottom = parseInt(rocket.style.bottom) || 0;
47+
if (currentBottom > 0) {
48+
rocket.style.bottom = (currentBottom - 10) + 'px';
49+
spaceShuttleHeight.textContent = parseInt(spaceShuttleHeight.textContent) - 10000;
50+
}
51+
});
52+
53+
rightButton.addEventListener('click', function() {
54+
let currentLeft = parseInt(rocket.style.left) || 0;
55+
rocket.style.left = (currentLeft + 10) + 'px';
56+
});
57+
58+
leftButton.addEventListener('click', function() {
59+
let currentLeft = parseInt(rocket.style.left) || 0;
60+
rocket.style.left = (currentLeft - 10) + 'px';
61+
});
62+
});

0 commit comments

Comments
 (0)