-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Expand file tree
/
Copy pathscripts.js
More file actions
82 lines (66 loc) · 2.87 KB
/
scripts.js
File metadata and controls
82 lines (66 loc) · 2.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
// Write your JavaScript code here.
// Remember to pay attention to page loading!
function init() {
let takeOffButton = document.getElementById("takeoff");
let landButton = document.getElementById("landing");
let status=document.getElementById("flightStatus");
let missionAbortButton=document.getElementById("missionAbort");
let up =document.getElementById("up");
let down = document.getElementById("down");
let right = document.getElementById("right");
let left = document.getElementById("left");
let shuttleHeight=document.getElementById("spaceShuttleHeight")
let imgObj=document.getElementById("rocket");
imgObj.style.position = 'absolute';
imgObj.style.bottom='0px';
imgObj.style.left='0px';
takeOffButton.addEventListener('click',function(event){
let response = window.confirm("Is the shuttle ready for takeoff");
if(response){
status.innerHTML= "Shuttle in flight.";
document.getElementById("shuttleBackground").style.backgroundColor = 'blue';
//spaceShuttleHeight
parseIntdocument.getElementById("spaceShuttleHeight").innerHTML=10000;
}
})
landButton.addEventListener('click',function(event){
window.alert("The shuttle is landing. Landing gear engaged");
status.innerHTML= "The shuttle has landed";
document.getElementById("shuttleBackground").style.backgroundColor = 'green';
document.getElementById("spaceShuttleHeight").innerHTML=0;
imgObj.style.position = 'absolute';
imgObj.style.bottom='0px';
imgObj.style.left='0px';
})
missionAbortButton.addEventListener('click',function(event){
let response = window.confirm("Confirm that you want to abort the mission.");
if(response){
status.innerHTML= "Mission aborted";
document.getElementById("shuttleBackground").style.backgroundColor = 'green';
//spaceShuttleHeight
document.getElementById("spaceShuttleHeight").innerHTML=0;
imgObj.style.position = 'absolute';
imgObj.style.bottom='0px';
imgObj.style.left='0px';
}
})
up.addEventListener('click',function(event){
let movement =parseInt(imgObj.style.bottom) + 10 + 'px';
imgObj.style.bottom = movement;
shuttleHeight.innerHTML= pareInt(shuttleHeight.innerHTML) + 10000;
})
down.addEventListener('click',function(){
let movement =parseInt(imgObj.style.bottom) - 10 + 'px';
imgObj.style.bottom = movement;
shuttleHeight.innerHTML= pareInt(shuttleHeight.innerHTML) - 10000;
})
right.addEventListener('click',function(){
let movement =parseInt(imgObj.style.left) + 10 + 'px';
imgObj.style.left = movement;
})
left.addEventListener('click',function(){
let movement =parseInt(imgObj.style.left) - 10 + 'px';
imgObj.style.left = movement;
})
}
window.addEventListener("load", init);