1
1
// Write your JavaScript code here.
2
+
2
3
// Remember to pay attention to page loading!
4
+ window . addEventListener ( "load" , function ( ) {
5
+
6
+ let rocket = document . getElementById ( "rocket" ) ;
7
+ rocket . style . position = "absolute" ;
8
+ rocket . style . bottom = "0px" ;
9
+ rocket . style . left = "270px" ;
10
+
11
+ let status = document . getElementById ( "flightStatus" ) ;
12
+ let background = document . getElementById ( "shuttleBackground" ) ;
13
+ let shuttleHeight = document . getElementById ( "spaceShuttleHeight" ) ;
14
+ const takeOff = document . getElementById ( "takeoff" ) ;
15
+
16
+ takeOff . addEventListener ( 'click' , event => {
17
+ let response = window . confirm ( "Confirm that the shuttle is ready for takeoff." ) ;
18
+ if ( response ) {
19
+ status . innerHTML = "Shuttle in flight." ;
20
+ background . style . backgroundColor = "blue" ;
21
+ shuttleHeight . innerHTML = "10000" ;
22
+ rocket . style . bottom = parseInt ( rocket . style . bottom ) + 10 + "px" ;
23
+ }
24
+ } ) ;
25
+ const land = document . getElementById ( "landing" ) ;
26
+ landing . addEventListener ( "click" , function ( ) {
27
+ window . alert ( "The shuttle is landing. Landing gear engaged." ) ;
28
+ status . innerHTML = "The shuttle has landed." ;
29
+ background . style . backgroundColor = "green" ;
30
+ innerHeight . innerHTML = "0" ;
31
+ rocket . style . bottom = "0px" ;
32
+
33
+ } ) ;
34
+
35
+ const up = document . getElementById ( "up" ) ;
36
+ const down = document . getElementById ( "down" ) ;
37
+ const right = document . getElementById ( "right" ) ;
38
+ const left = document . getElementById ( "left" ) ;
39
+
40
+ const abort = document . getElementById ( "missionAbort" ) ;
41
+ abort . addEventListener ( "click" , function ( ) {
42
+ let toAbort = window . confirm ( "Confirm that you want to abort the mission." ) ;
43
+ if ( toAbort ) {
44
+ status . innerHTML = "Mission aborted." ;
45
+ background . style . backgroundColor = "red" ;
46
+ height . innerHTML = "0" ;
47
+ rocket . style . bottom = "0px" ;
48
+ rocket . style . left = "270px" ;
49
+ }
50
+ } ) ;
51
+
52
+ up . addEventListener ( "click" , function ( ) {
53
+ if ( status . innerHTML === "Shuttle in flight." && parseInt ( shuttleHeight . innerHTML ) < 250000 ) {
54
+ rocket . style . bottom = parseInt ( rocket . style . bottom ) + 10 + "px" ;
55
+ shuttleHeight . innerHTML = parseInt ( shuttleHeight . innerHTML ) + 10000 ;
56
+ }
57
+ } ) ;
58
+
59
+ down . addEventListener ( "click" , function ( ) {
60
+ if ( status . innerHTML === "Shuttle in flight." && parseInt ( shuttleHeight . innerHTML ) !== 0 ) {
61
+ rocket . style . bottom = parseInt ( rocket . style . bottom ) - 10 + "px" ;
62
+ shuttleHeight . innerHTML = parseInt ( shuttleHeight . innerHTML ) - 10000 ;
63
+ }
64
+ } ) ;
65
+
66
+ right . addEventListener ( "click" , function ( ) {
67
+ if ( status . innerHTML === "Shuttle in flight." ) {
68
+ rocket . style . left = parseInt ( rocket . style . left ) + 10 + "px" ;
69
+ }
70
+ } ) ;
71
+
72
+ left . addEventListener ( "click" , function ( ) {
73
+ if ( status . innerHTML === "Shuttle in flight." ) {
74
+ rocket . style . left = parseInt ( rocket . style . left ) - 10 + "px" ;
75
+ }
76
+ } ) ;
77
+
78
+
79
+ } ) ;
0 commit comments