Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 2 additions & 27 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,36 +7,11 @@
</head>
<body>
<h1>Launch Checklist Form</h1>
<div id="missionTarget">
<div id="missioorfnTarget">
<!-- Fetch some planetary data -->
</div>
<div id="launchForm">
<form>
<div style="display:flex; flex-direction: row; justify-content: center; align-items: center; margin: 8 0;">
<label>Pilot Name <input type="text" name="pilotName" id="pilotName"/></label>
</div>
<div style="display:flex; flex-direction: row; justify-content: center; align-items: center; margin: 8 0;">
<label>Co-pilot Name <input type="text" name="copilotName"/></label>
</div>
<div style="display:flex; flex-direction: row; justify-content: center; align-items: center; margin: 8 0;">
<label>Fuel Level (L) <input type="text" name="fuelLevel"/></label>
</div>
<div style="display:flex; flex-direction: row; justify-content: center; align-items: center; margin: 8 0;">
<label>Cargo Mass (kg) <input type="text" name="cargoMass"/></label>
</div>
<button id="formSubmit">Submit</button>
</form>
</div>
<div id="launchStatusCheck">
<h2 id="launchStatus">Awaiting Information Before Launch</h2>
<div id="faultyItems">
<ol>
<li id="pilotStatus">Pilot Ready</li>
<li id="copilotStatus">Co-pilot Ready</li>
<li id="fuelStatus">Fuel level high enough for launch</li>
<li id="cargoStatus">Cargo mass low enough for launch</li>
</ol>
</div>
</div>
</body>
</html>

77 changes: 67 additions & 10 deletions script.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,70 @@
// Write your JavaScript code here!

/* This block of code shows how to format the HTML once you fetch some planetary JSON!
<h2>Mission Destination</h2>
window.addEventListener("load", function() {
let pilotName = document.getElementById("pilotName");
let copilotName = document.getElementById("copilotName");
let fuelLevel = document.getElementById("fuelLevel");
let cargoMass = document.getElementById("cargoMass");
let json=[];
fetch("https://handlers.education.launchcode.org/static/planets.json").then(function(response) {
response.json().then(function(json) {
const div = document.getElementById("missionTarget");
let index = Math.floor(Math.random()*json.length);
div.innerHTML += `
<h2>Mission Destination</h2>
<ol>
<li>Name: ${}</li>
<li>Diameter: ${}</li>
<li>Star: ${}</li>
<li>Distance from Earth: ${}</li>
<li>Number of Moons: ${}</li>
<li>Name: ${json[index].name}</li>
<li>Diameter: ${json[index].diameter}</li>
<li>Star: ${json[index].star}</li>
<li>Distance from Earth: ${json[index].distance}</li>
<li>Number of Moons: ${json[index].moons}</li>
</ol>
<img src="${}">
*/
<img src="${json[index].image}"></img>
`

});
});


let form = document.querySelector("form");
form.addEventListener("submit", function(event){

if (pilotName.value === "" || copilotName.value === "" || fuelLevel.value === "" || cargoMass.value === "") {
alert("All fields are required!");
event.preventDefault();
} else if( isNaN(pilotName.value) === false || isNaN(copilotName.value) === false || isNaN(fuelLevel.value) === true || isNaN(cargoMass.value) === true) {
alert("PLease enter valid information");
event.preventDefault();
} else {
pilotStatus.innerHTML = `Pilot Name ${pilotName.value} is READY.`;
copilotStatus.innerHTML = `Copilot Name ${copilotName.value} is READY`;
};


if(fuelLevel.value < 10000 || cargoMass.value > 10000 ) {
launchStatus.style.color = "red";
launchStatus.innerHTML = `Shuttle not ready for launch.`;
event.preventDefault();

if (fuelLevel.value < 1000) {
faultyItems.style.visibility= 'visible';
fuelStatus.innerHTML =`Not enough fuel for the journey!`;
event.preventDefault();
} else if (cargoMass.value > 10000) {
faultyItems.style.visibility= 'visible';
cargoStatus.innerHTML =`Too much cargo!`;
event.preventDefault();

};
} else {
launchStatus.style.color = "green";
launchStatus.innerHTML = `Shuttle is ready for launch.`;
event.preventDefault();
};
});
});