Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Checklist form branch1 #9

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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
15 changes: 15 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "pwa-chrome",
"request": "launch",
"name": "Launch Chrome against localhost",
"url": "http://localhost:8080",
"webRoot": "${workspaceFolder}"
}
]
}
1 change: 1 addition & 0 deletions debug.log
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[1023/160135.842:ERROR:directory_reader_win.cc(43)] FindFirstFile: The system cannot find the path specified. (0x3)
81 changes: 42 additions & 39 deletions index.html
Original file line number Diff line number Diff line change
@@ -1,42 +1,45 @@
<!DOCTYPE>
<html>
<head>
<title>Launch Checklist</title>
<link rel = "stylesheet" type = "text/css" href = "styles.css" />
<script src = "script.js"></script>
</head>
<body>
<h1>Launch Checklist Form</h1>
<div id="missionTarget">
<!-- 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>

<head>
<title>Launch Checklist</title>
<link rel="stylesheet" type="text/css" href="styles.css" />
<script src="script.js"></script>
</head>

<body>
<h1>Launch Checklist Form</h1>
<div id="missionTarget">
<!-- 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>
</body>
</html>
<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>
91 changes: 82 additions & 9 deletions script.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,86 @@
// 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>
<ol>
<li>Name: ${}</li>
<li>Diameter: ${}</li>
<li>Star: ${}</li>
<li>Distance from Earth: ${}</li>
<li>Number of Moons: ${}</li>
</ol>
<img src="${}">

*/
function getPlanetaryInfo() {
let url = "https://handlers.education.launchcode.org/static/planets.json";
let missionTargetDiv = document.getElementById("missionTarget");
fetch(url).then(function (response) {
response.json().then(function (json) {
let planetInfo = json[Math.floor(Math.random() * json.length)];
missionTargetDiv.innerHTML = `<h2>Mission Destination</h2>
<ol>
<li>Name: ${planetInfo.name}</li>
<li>Diameter: ${planetInfo.diameter}</li>
<li>Star: ${planetInfo.star}</li>
<li>Distance from Earth: ${planetInfo.distance}</li>
<li>Number of Moons: ${planetInfo.moons}</li>
</ol>
<img src="${planetInfo.image}">`

});
});
}

window.addEventListener("load", function () {
getPlanetaryInfo();

let form = document.querySelector("form");
form.addEventListener("submit", function (event) {
let pilotNameInput = document.querySelector("input[name=pilotName]");
let copilotNameInput = document.querySelector("input[name=copilotName]");
let fuelLevelInput = document.querySelector("input[name=fuelLevel]");
let cargoMassInput = document.querySelector("input[name=cargoMass]");


if (pilotNameInput.value === "" || copilotNameInput.value === "" || fuelLevelInput.value === "" || cargoMassInput.value === "") {
alert("All fields are required");
event.preventDefault();
return;
}
if (!(isNaN(pilotNameInput.value) && isNaN(copilotNameInput.value))) {
alert("Pilot & co-pilot names should not be number");
event.preventDefault();
return;
}

if (isNaN(fuelLevelInput.value) || isNaN(cargoMassInput.value)) {
alert("FuelLevel & CargoMass should not be text");
event.preventDefault();
return;
}

let faultyItemsDiv = document.getElementById("faultyItems");
let launchStatusDiv = document.getElementById("launchStatus");

if (fuelLevelInput.value < 10000) {
document.getElementById("fuelStatus").innerHTML = `Fuel level too low for launch`;
}
else{
document.getElementById("fuelStatus").innerHTML = `Fuel level high enough for launch`;
}

if (cargoMassInput.value > 10000) {
document.getElementById("cargoStatus").innerHTML = `Cargo mass high for launch`;
}
else{
document.getElementById("cargoStatus").innerHTML = `Cargo mass low enough for launch`;
}

if (fuelLevelInput.value < 10000 || cargoMassInput.value > 10000) {
launchStatusDiv.innerHTML = "Shuttle not ready for launch";
launchStatusDiv.style.color = "red";

}
else {
launchStatusDiv.innerHTML = "Shuttle is ready for launch";
launchStatusDiv.style.color = "green";
}

faultyItemsDiv.style.visibility = 'visible';
document.getElementById("pilotStatus").innerHTML = `Pilot ${pilotNameInput.value} is ready for launch`;
document.getElementById("copilotStatus").innerHTML = `Co-pilot ${copilotNameInput.value} is ready for launch`;
event.preventDefault();
});
});