Repository navigation
Expand file tree
/
Copy pathscript.js
More file actions
120 lines (112 loc) · 5.21 KB
/
Copy pathscript.js
File metadata and controls
120 lines (112 loc) · 5.21 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
// Write your JavaScript code here!
window.addEventListener("load", function() {
// let form = document.querySelector("form");
fetch("https://handlers.education.launchcode.org/static/planets.json").then(function(response) {
response.json().then(function(json) {
console.log(response);
const div = document.getElementById('missionTarget');
// Add HTML that includes the JSON Data ${json[2].
div.innerHTML = `
<h2>Mission Destination</h2>
<ol>
<li>Name: ${json[2].name}</li>
<li>Diameter: ${json[2].diameter}</li>
<li>Star: ${json[2].star}</li>
<li>Distance from Earth: ${json[2].distance}</li>
<li>Number of Moons: ${json[2].moons}</li>
</ol>
<img src=${json[2].image}>
`
});
});
console.log('window loaded');
// function init() {
let form = document.getElementById("launchform");
let button = document.getElementById("formSubmit");
button.addEventListener("click", function (event) {
console.log('form submit');
event.preventDefault();
let pilotStatus = document.getElementById("pilotStatus");
let copilotStatus = document.getElementById("copilotStatus");
let fuelStatus = document.getElementById("fuelStatus");
let cargoStatus = document.getElementById("cargoStatus");
let launchStatus = document.getElementById("launchStatus");
let faultyItems = document.getElementById("faultyItems");
let pilotName = document.getElementById("pilotName");
let copilotName = document.getElementById("copilotName");
let fuelLevel = document.getElementById("fuelLevel");
let cargoWeight = document.getElementById("cargoWeight");
let launchStatusCheck = true;
if(cargoWeight.value === "" || fuelLevel.value === ""
|| pilotName.value === "" || copilotName.value === "") {
alert("all fields are required!");
return;
// event.preventDefault();
}
if(isNaN(cargoWeight.value) || isNaN(fuelLevel.value)) {
alert("Make sure to enter valid information for each field!");
return;
// event.preventDefault();
}
if(Number.isInteger(Number(pilotName.value)) || Number.isInteger(Number(copilotName.value))) {
alert("Make sure to enter valid information for each field!");
return;
// event.preventDefault();
}else{
if(pilotName.value !== "") {
pilotStatus.innerHTML = "Pilot " + pilotName.value + " is ready for launch"
}
if(copilotName.value !== "") {
copilotStatus.innerHTML = "Co-pilot " + copilotName.value + " is ready for launch"
}
}
console.log(fuelLevel.value, 'fuel');
if (fuelLevel.value < 10000) {
faultyItems.style.visibility = "visible";
launchStatusCheck = false;
fuelStatus.innerHTML = "not enough fuel for the journey"
launchStatus.innerHTML = "Shuttle not ready for launch"
launchStatus.setAttribute("class", "launchStatusInvalid");
} else {
launchStatusCheck = true;
fuelStatus.innerHTML ="Fuel level high enough for launch";
}
if (cargoWeight.value > 10000) {
faultyItems.style.visibility = "visible";
launchStatusCheck = false;
cargoStatus.innerHTML = "too much mass for the shuttle to take off"
launchStatus.innerHTML = "Shuttle not ready for launch"
launchStatus.setAttribute("class", "launchStatusInvalid");
} else {
if (fuelLevel.value >= 10000) {
launchStatusCheck = true;
}
cargoStatus.innerHTML ="Cargo weight low enough for launch";
}
if (launchStatusCheck === true) {
launchStatus.innerHTML = "Shuttle is ready for launch"
launchStatus.setAttribute("class", "launchStatusValid");
}
// if (fuelLevel === 890) {
// fuelStatus.innerHTML = "not enough fuel for the journey"
// launchStatus.innerHTML = "Shuttle not ready for launch"
// launchStatus.attr("id", "launchStatusInvalid"); -890 liters of fuel part
// }
console.log("alert");
// function submitButtonClicked() {
// document.getElementById("submitButton").innerHTML += "submitButtonClicked...";
// if (launchStatusValid === true) {
// document.getElementById('submitButton').enabled = true;
// }
// }
// document.getElementById("form").submit();
// button.addEventListener("click", submitButton);
// // <!-- <button ="alert('submit')" enabled="enabled" -->
// // <button onclick="console.log('submit...');">Submit</button>
// console.log("submit button clicked");
});
// });
// }
// window.onload = init;
});
/* This block of code shows how to format the HTML once you fetch some planetary JSON! */