Skip to content

Commit 40f3994

Browse files
Charlene TranCharlene Tran
Charlene Tran
authored and
Charlene Tran
committed
completed - working on Bonus Mission
1 parent 623eabf commit 40f3994

File tree

1 file changed

+41
-14
lines changed

1 file changed

+41
-14
lines changed

dom-and-events/studio-CT/scripts.js

Lines changed: 41 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,17 @@ function init () {
1212
const buttonLeft = this.document.getElementById("left");
1313
const rocket = this.document.getElementById("rocket"), left = 0;
1414

15-
16-
1715
let flightStatus = this.document.getElementById("flightStatus")
1816
let shuttleBackgroundColor = this.document.getElementById("shuttleBackground");
1917
let shuttleHeightMiles = this.document.getElementById("spaceShuttleHeight");
18+
let currentPosition = 0;
19+
let currentShuttleHeight = 0;
20+
21+
rocket.style.left = "0";
22+
rocket.style.position = "absolute";
2023

2124

25+
// When "Take off" button is clicked
2226
buttonTakeOff.addEventListener("click", function(event) {
2327
let response = window.confirm("Confirm that the shuttle is ready for takeoff.");
2428

@@ -30,16 +34,19 @@ function init () {
3034
});
3135

3236

37+
// When "Land" button is clicked
3338
buttonLanding.addEventListener("click", function(event) {
3439
window.alert("The shuttle is landing. Landing gear engaged.");
3540

3641
flightStatus.innerHTML = "The shuttle has landed.";
3742
shuttleBackgroundColor.style.backgroundColor = "green";
3843
shuttleHeightMiles.innerHTML = "0";
3944

45+
4046
});
4147

4248

49+
// When "Abort Mission" button is clicked
4350
buttonMissionAbort.addEventListener("click", function(event) {
4451
let response = window.confirm("Confirm that you want to abort the mission.");
4552

@@ -50,31 +57,51 @@ function init () {
5057
}
5158
});
5259

53-
60+
61+
// When "Right" button is clicked
5462
buttonRight.addEventListener("click", function(event) {
5563

56-
rocket.style.position = "absolute";
57-
let currentPosition = parseInt(rocket.style.left);
58-
59-
rocket.style.left = currentPosition + 10;
60-
64+
currentPosition = parseInt(rocket.style.left);
65+
rocket.style.left = (currentPosition + 10) + "px";
6166

62-
console.log(typeof rocket.style.position);
67+
console.log(rocket.style.left); // Used for testing output
68+
});
6369

64-
console.log("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
6570

66-
console.log(rocket.style.left);
67-
console.log(typeof rocket.style.left);
71+
// When "Left" button is clicked
72+
buttonLeft.addEventListener("click",function(event) {
6873

69-
// rocket.setAttribute("right", rightPosition);
74+
currentPosition = parseInt(rocket.style.left);
7075

76+
if (currentPosition > 0) {
77+
rocket.style.left = (currentPosition - 10) + "px";
78+
} else {
79+
console.log("Unable to move LEFT. Try again!");
80+
}
81+
82+
console.log(rocket.style.left);
7183
});
7284

7385

86+
// When "Up" button is clicked
87+
buttonUp.addEventListener("click", function(event) {
7488

89+
currentShuttleHeight = parseInt(shuttleHeightMiles.innerHTML);
90+
shuttleHeightMiles.innerHTML = currentShuttleHeight + 10000;
91+
92+
});
7593

7694

77-
95+
// When "Down" button is clicked
96+
buttonDown.addEventListener("click", function(event) {
97+
currentShuttleHeight = parseInt(shuttleHeightMiles.innerHTML);
98+
99+
if (currentShuttleHeight > 10) {
100+
shuttleHeightMiles.innerHTML = currentShuttleHeight - 10000;
101+
} else {
102+
console.log("Unable to move DOWN, Try again!");
103+
}
104+
});
78105
};
79106

80107

0 commit comments

Comments
 (0)