diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 00000000..7a9dfa04 --- /dev/null +++ b/.vscode/launch.json @@ -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}" + } + ] +} \ No newline at end of file diff --git a/debug.log b/debug.log new file mode 100644 index 00000000..282ffde5 --- /dev/null +++ b/debug.log @@ -0,0 +1 @@ +[1023/160135.842:ERROR:directory_reader_win.cc(43)] FindFirstFile: The system cannot find the path specified. (0x3) diff --git a/index.html b/index.html index bc185ad2..5c0f01a5 100644 --- a/index.html +++ b/index.html @@ -1,42 +1,45 @@ - - Launch Checklist - - - - -

Launch Checklist Form

-
- -
-
-
-
- -
-
- -
-
- -
-
- -
- -
-
-
-

Awaiting Information Before Launch

-
-
    -
  1. Pilot Ready
  2. -
  3. Co-pilot Ready
  4. -
  5. Fuel level high enough for launch
  6. -
  7. Cargo mass low enough for launch
  8. -
+ + + Launch Checklist + + + + + +

Launch Checklist Form

+
+ +
+
+
+
+ +
+
+ +
+
+
-
- - +
+ +
+ + +
+
+

Awaiting Information Before Launch

+
+
    +
  1. Pilot Ready
  2. +
  3. Co-pilot Ready
  4. +
  5. Fuel level high enough for launch
  6. +
  7. Cargo mass low enough for launch
  8. +
+
+
+ + + \ No newline at end of file diff --git a/script.js b/script.js index 8d2e0821..88c50c01 100644 --- a/script.js +++ b/script.js @@ -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! -

Mission Destination

-
    -
  1. Name: ${}
  2. -
  3. Diameter: ${}
  4. -
  5. Star: ${}
  6. -
  7. Distance from Earth: ${}
  8. -
  9. Number of Moons: ${}
  10. -
- + */ +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 = `

Mission Destination

+
    +
  1. Name: ${planetInfo.name}
  2. +
  3. Diameter: ${planetInfo.diameter}
  4. +
  5. Star: ${planetInfo.star}
  6. +
  7. Distance from Earth: ${planetInfo.distance}
  8. +
  9. Number of Moons: ${planetInfo.moons}
  10. +
+ ` + + }); + }); +} + +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(); + }); +}); \ No newline at end of file