Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,16 @@ <h3>Astronaut Chat</h3>
<img src = "LaunchCode_rocketline_white.png" height = "75" width = "75" id = "rocket"/>
</div>
<div style = "text-align: center; display: inline-block;">
<button>Up</button>
<button>Down</button>
<button>Right</button>
<button>Left</button>
<button id = "up">Up</button>
<button id = "down">Down</button>
<button id = "right">Right</button>
<button id ="left">Left</button>
<h3>Space Shuttle Height</h3>
<p id="spaceShuttleHeight">0</p><p style = "display: inline-block;"> miles</p>
</div>
</div>
<div style="text-align: center;">
<button id = "takeoff">Take off</button>
<button id = "takeOff">Take off</button>
<button id = "landing">Land</button>
<button id = "missionAbort">Abort Mission</button>
</div>
Expand Down
69 changes: 68 additions & 1 deletion scripts.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,69 @@
// Write your JavaScript code here.
// Remember to pay attention to page loading!
// Remember to pay attention to page loading!

window.addEventListener("load", function(){
let status = this.document.getElementById("flightStatus");
let bg = this.document.getElementById("shuttleBackground");
let shuttleHeight = this.document.getElementById("spaceShuttleHeight");
let rocketImg = this.document.getElementById("rocket");
rocketImg.style.position = "absolute";
rocketImg.style.left = "0px";
rocketImg.style.bottom = "0px";

let left = this.document.getElementById("left");
left.addEventListener("click", function(){
if (parseInt(rocketImg.style.left) > 0){
rocketImg.style.left = parseInt(rocketImg.style.left) - 10 + "px";
}
})

let right = this.document.getElementById("right");
right.addEventListener("click", function(){
if (parseInt(rocketImg.style.left) < 300){
rocketImg.style.left = parseInt(rocketImg.style.left) + 10 + "px";
}
})

let up = this.document.getElementById("up");
up.addEventListener("click", function(){
if (parseInt(rocketImg.style.bottom) < 250) {
rocketImg.style.bottom = parseInt(rocketImg.style.bottom) + 10 + "px";
shuttleHeight.innerHTML = parseInt(shuttleHeight.innerHTML) + 10000;
}
})
let down = this.document.getElementById("down");
down.addEventListener("click", function(){
if (parseInt(rocketImg.style.bottom) > 0) {
rocketImg.style.bottom = parseInt(rocketImg.style.bottom) - 10 + "px";
shuttleHeight.innerHTML = parseInt(shuttleHeight.innerHTML) - 10000;
}
})

let takeOff = this.document.getElementById("takeOff");
takeOff.addEventListener("click", function(){
if (window.confirm("Are you sure the shuttle is ready for takeoff?")){
status.innerHTML = "Shuttle in flight";
bg.style.backgroundColor = "blue";
shuttleHeight.innerHTML = "10000";
}
})

let landing = this.document.getElementById("landing");
landing.addEventListener("click", function(){
window.alert("The shuttle is landing. landing gear engaged.");
status.innerHTML = "Shuttle landed";
bg.style.backgroundColor = "green";
shuttleHeight.innerHTML = "0";
rocketImg.style.bottom = "0px";
})

let missionAbort = this.document.getElementById("missionAbort");
missionAbort.addEventListener("click", function(){
window.alert("Confirm that you want to abort the mission.");
status.innerHTML = "Mission aborted";
bg.style.backgroundColor = "green";
shuttleHeight.innerHTML = "0";

})

})