-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscriptHelper.js
More file actions
89 lines (75 loc) · 3.56 KB
/
scriptHelper.js
File metadata and controls
89 lines (75 loc) · 3.56 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
// Write your helper functions here!
require('isomorphic-fetch');
function addDestinationInfo(document, name, diameter, star, distance, moons, imageUrl) {
// Here is the HTML formatting for our mission target div.
document.getElementById("missionTarget").innerHTML = `
<h2>Mission Destination</h2>
<ol>
<li>Name:${name} </li>
<li>Diameter:${diameter} </li>
<li>Star: ${star}</li>
<li>Distance from Earth:${distance} </li>
<li>Number of Moons:${moons} </li>
</ol>
<img src="${imageUrl}">
`;
}
function validateInput(testInput) {
//testInput = "";
if(testInput === ""){
return "Empty";
}
else if(isNaN(testInput)){
return "Not a Number";
}
else if(!isNaN(testInput)){
return "Is a Number";
}
}
function formSubmission(document, list, pilot, copilot, fuelLevel, cargoLevel) {
// Possibly work needed on if else if statements
document.getElementById("pilotStatus").innerHTML = `Pilot ${pilot} is ready for launch`;
document.getElementById("copilotStatus").innerHTML = `Co-pilot ${copilot} is ready for launch`;
document.getElementById("fuelStatus").innerHTML = "Fuel level high enough for launch";
document.getElementById("cargoStatus").innerHTML = "Cargo mass low enough for launch";
if(fuelLevel < 10000){
document.getElementById("faultyItems").style.visibility = "visible";
document.getElementById("fuelStatus").innerHTML = "Fuel level too low for launch";
document.getElementById("launchStatus").style.color = "rgb(199, 37, 78)";
document.getElementById("launchStatus").innerHTML = "Shuttle Not Ready for Launch";
}
if(cargoLevel > 10000){
document.getElementById("faultyItems").style.visibility = "visible";
document.getElementById("cargoStatus").innerHTML = "Cargo mass too heavy for launch";
document.getElementById("launchStatus").style.color = "rgb(199, 37, 78)";
document.getElementById("launchStatus").innerHTML = "Shuttle Not Ready for Launch";
}
else if(fuelLevel < 10000 && cargoLevel > 10000){
document.getElementById("faultyItems").style.visibility = "visible";
document.getElementById("fuelStatus").innerHTML = "Fuel level too low for launch";
document.getElementById("cargoStatus").innerHTML = "Cargo mass too heavy for launch";
document.getElementById("launchStatus").style.color = "rgb(199, 37, 78)";
document.getElementById("launchStatus").innerHTML = "Shuttle Not Ready for Launch";
}
else if(fuelLevel >= 10000 && cargoLevel <= 10000){
document.getElementById("faultyItems").style.visibility = "visible";
document.getElementById("launchStatus").style.color = "rgb(65, 159, 106)";
document.getElementById("launchStatus").innerHTML = "Shuttle is Ready for Launch";
}
}
async function myFetch() {
let planetsReturned;
planetsReturned = await fetch("https://handlers.education.launchcode.org/static/planets.json").then( function(response) {
return response.json();
});
return planetsReturned;
}
function pickPlanet(planets) {
let planetNumber = Math.floor(Math.random() * planets.length);
return planets[planetNumber];
}
module.exports.addDestinationInfo = addDestinationInfo;
module.exports.validateInput = validateInput;
module.exports.formSubmission = formSubmission;
module.exports.pickPlanet = pickPlanet;
module.exports.myFetch = myFetch;