From f9b20bd3c7b12cbd0d1f9ede9b8ad4116ac45172 Mon Sep 17 00:00:00 2001 From: Hilola Date: Thu, 15 Jul 2021 23:06:13 -0500 Subject: [PATCH] Studio assignment done. --- index.html | 10 ++++---- scripts.js | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 73 insertions(+), 6 deletions(-) diff --git a/index.html b/index.html index b5292e2..c8de774 100644 --- a/index.html +++ b/index.html @@ -23,16 +23,16 @@

Astronaut Chat

- - - - + + + +

Space Shuttle Height

0

miles

- +
diff --git a/scripts.js b/scripts.js index cdba002..a848e48 100644 --- a/scripts.js +++ b/scripts.js @@ -1,2 +1,69 @@ // Write your JavaScript code here. -// Remember to pay attention to page loading! \ No newline at end of file +// 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"; + +}) + +}) \ No newline at end of file