forked from LaunchCodeEducation/Launch-Checklist-Form
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
86 lines (66 loc) · 3.02 KB
/
script.js
File metadata and controls
86 lines (66 loc) · 3.02 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
window.addEventListener("load", function() {
let form = document.querySelector("form");
form.addEventListener("submit", function(event) {
let nameOfPilot = document.querySelector("input[name=pilotName]");
let nameOfCoPilot = document.querySelector("input[name=copilotName]");
let fuelLevelInput = document.querySelector("input[name=fuelLevel]");
let cargoMassInput = document.querySelector("input[name=cargoMass]");
if(nameOfPilot.value === "" || nameOfCoPilot.value === "" || fuelLevelInput.value === "" || cargoMassInput.value === ""){
alert("All fields are required!");
}
if(isNaN(fuelLevelInput.value) || isNaN(cargoMassInput.value)){
alert("Need to input a number");
}
let parse = parseInt(nameOfPilot.value)
let parseCO = parseInt(nameOfCoPilot.value)
if(!isNaN(parse) || !isNaN(parseCO)){
alert("Need to use letters");
}
let statusOfPilot = document.getElementById("pilotStatus");
let statusOfCoPilot = document.getElementById("copilotStatus");
let statusOfFuel = document.getElementById("fuelStatus");
let statusOfLaunch = document.getElementById("launchStatus");
let statusOfMass = document.getElementById("cargoStatus")
if(nameOfPilot){
statusOfPilot.innerHTML = `Pilot ${nameOfPilot.value} is Ready`
}
if(nameOfCoPilot){
statusOfCoPilot.innerHTML = `Co-pilot ${nameOfCoPilot.value} is Ready`
event.preventDefault();
}
if("formSubmit"){
faultyItems.style.visibility = "visible";
}
if(parseInt(fuelLevelInput.value) < 10000){
statusOfFuel.innerHTML = `There is not enough fuel for the journey.`
statusOfLaunch.innerHTML = `Shuttle not ready for launch`
statusOfLaunch.style.color = "red"
}
if(parseInt(cargoMassInput.value) > 10000){
statusOfMass.innerHTML = `There is too much mass for the shuttle to take off`
statusOfLaunch.innerHTML = `Shuttle not ready for launch`
statusOfLaunch.style.color = "red"
}
if(parseInt(fuelLevelInput.value) > 10000 && parseInt(cargoMassInput.value) < 10000 ){
statusOfLaunch.innerHTML = `Shuttle is ready for launch`
statusOfLaunch.style.color = "green"
}
});
});
window.addEventListener("load", function(){
fetch("https://handlers.education.launchcode.org/static/planets.json").then(function(response){
response.json().then(function(json){
let targetOfMission = document.getElementById("missionTarget");
targetOfMission.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}>`
});
});
});