Skip to content

Commit 02bedfa

Browse files
Quinton KornegayQuinton Kornegay
Quinton Kornegay
authored and
Quinton Kornegay
committed
going live
2 parents cc6b456 + 79489f8 commit 02bedfa

File tree

2 files changed

+78
-2
lines changed

2 files changed

+78
-2
lines changed

dom-and-events/studio/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ <h1>Flight Simulator</h1>
1111
<h2>Current Flight Status</h2>
1212
<p id = "flightStatus">Space shuttle ready for takeoff</p>
1313
<h2>Shuttle Trajectory</h2>
14-
</div>
14+
</div>
1515
<div id="flightDisplay">
1616
<div class="center-block">
1717
<h3>Fuel Levels</h3>
@@ -20,7 +20,7 @@ <h3>Astronaut Chat</h3>
2020
<p>Houston, we are ready when you are!</p>
2121
</div>
2222
<div id = "shuttleBackground">
23-
<img src = "LaunchCode_rocketline_white.png" height = "75" width = "75" id = "rocket"/>
23+
<img src = "LaunchCode_rocketline_white.png" height = "75" width = "75" id = "rocket" style = "position: absolute; bottom: 0; left: calc(50% - 38px)"/>
2424
</div>
2525
<div class="center-block">
2626
<button id="up">Up</button>

dom-and-events/studio/scripts.js

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,78 @@
11
// Write your JavaScript code here.
22
// Remember to pay attention to page loading!
3+
window.addEventListener("load", function() {
4+
5+
let altitude = 0;
6+
let rocketPosX = 0;
7+
let rocketPosY = 0;
8+
9+
// BUTTONS
10+
const takeoffButton = document.getElementById('takeoff');
11+
const landButton = document.getElementById('landing');
12+
const abortButton = document.getElementById('missionAbort');
13+
14+
// AREAS
15+
const flightStatus = document.getElementById('flightStatus');
16+
const shuttleBackground = document.getElementById('shuttleBackground');
17+
const spaceShuttleHeight = document.getElementById('spaceShuttleHeight');
18+
19+
// ROCKET IMAGE
20+
const rocket = document.getElementById('rocekt');
21+
22+
23+
takeoffButton.addEventListener("click", function() {
24+
let shouldTakeOff = confirm("Confirm that the shuttle is ready for takeoff.");
25+
26+
if (shouldTakeOff) {
27+
flightStatus.innerHTML = "Shuttle in flight.";
28+
shuttleBackground.style.backgroundColor = "blue";
29+
altitude = 10000;
30+
spaceShuttleHeight.innerHTML = altitude;
31+
}
32+
});
33+
34+
landButton.addEventListener("click", function(){
35+
alert("The shuttle is landing. Landing gear engaged.");
36+
flightStatus.innerHTML = "The shuttle has landed.";
37+
shuttleBackground.style.backgroundColor = "green";
38+
altitude = 0;
39+
spaceShuttleHeight.innerHTML = altitude;
40+
});
41+
42+
abortButton.addEventListener("click", function(){
43+
let shouldAbort = confirm("Confirm that you want to abort the mission.")
44+
45+
if(shouldAbort) {
46+
flightStatus.innerHTML = "Mission aborted.";
47+
shuttleBackground.style.backgroundColor = "green";
48+
altitude = 0;
49+
spaceShuttleHeight.innerHTML = altitude;
50+
}
51+
});
52+
53+
this.document.addEventListener("click", function(event){
54+
let bkgWidth = parseInt(window.getComputedStyle(shuttleBackground).getPropertyValue('Width'));
55+
56+
if (event.target.id === "left" && rocketPosX > -(bkgWidth / 2 - 40)) {
57+
rocketPosX -= 10;
58+
rocket.style.marginLeft = rocketPosX + 'px';
59+
}
60+
if (event.target.id === "right" && rocketPosX < (bkgWidth / 2 - 40)) {
61+
rocketPosX += 10;
62+
rocket.style.marginLeft = rocketPosX + 'px';
63+
}
64+
if (event.target.id === "up" && altitude <250000) {
65+
rocketPosY += 10;
66+
rocket.style.marginBottom = rocketPosY + 'px';
67+
altitude += 10000;
68+
spaceShuttleHeight.innerHTML = altitude;
69+
}
70+
if (event.target.id === "down" && altitude > 0) {
71+
rocketPosY -= 10;
72+
rocket.style.marginBottom = rocketPosY + 'px';
73+
altitude -= 10000;
74+
spaceShuttleHeight.innerHTML = altitude;
75+
}
76+
});
77+
78+
});

0 commit comments

Comments
 (0)