+
+
diff --git a/script.js b/script.js
index 8d2e0821..a33cb11c 100644
--- a/script.js
+++ b/script.js
@@ -1,13 +1,87 @@
-// Write your JavaScript code here!
-
-/* This block of code shows how to format the HTML once you fetch some planetary JSON!
-
Mission Destination
-
-
Name: ${}
-
Diameter: ${}
-
Star: ${}
-
Distance from Earth: ${}
-
Number of Moons: ${}
-
-
-*/
+// Write your JavaScript code here!
+
+// {/* /* This block of code shows how to format the HTML once you fetch some planetary JSON!
+function randomizer(max){
+ return Math.floor(Math.random() * Math.floor(max));
+}
+
+window.addEventListener("load",function() {
+ let form = document.getElementById("launchForm")
+ form.addEventListener("submit",function(event){
+ fetch("https://handlers.education.launchcode.org/static/planets.json").then( function(response) {
+ response.json().then( function(json) {
+ let i = randomizer(6);
+ const div = document.getElementById("missionTarget");
+ div.innerHTML= `
+
Mission Destination
+
+
Name: ${json[i].name}
+
Diameter: ${json[i].diameter}
+
Star: ${json[i].star}
+
Distance from Earth: ${json[i].distance}
+
Number of Moons: ${json[i].moons}
+
+ `
+ });
+ });
+let pilot = document.querySelector("input[name=pilotName]");
+let copilot = document.querySelector("input[name=copilotName]");
+let fuel = document.querySelector("input[name=fuelLevel]");
+let cargo =document.querySelector("input[name=cargoMass]");
+
+ if (pilot.value === "" || copilot.value === "" || fuel.value === "" || cargo.value === ""){
+ window.alert("All Fields are Required!");
+ event.preventDefault();
+ }else if(isNaN(fuel.value)||isNaN(cargo.value)){
+ window.alert("Please Enter a Number for Cargo and Fuel Levels!");
+ event.preventDefault();
+ }else if(isNaN(pilot.value) === false ||isNaN(copilot.value) === false){
+ window.alert("Please Enter a Valid Name for the Pilot and Copilot");
+ event.preventDefault();
+ }
+ });
+ form.addEventListener("submit",function(event){
+ let pilot = document.querySelector("input[name=pilotName]");
+ let copilot = document.querySelector("input[name=copilotName]");
+ let fuel = document.querySelector("input[name=fuelLevel]");
+ let cargo =document.querySelector("input[name=cargoMass]");
+
+ if (fuel.value < 10000 && fuel.value > 0){
+ launchStatus.innerHTML = "Shuttle not ready for launch"
+ faultyItems.style.visibility = 'visible';
+ launchStatus.style.color = 'red';
+ faultyItems.innerHTML= `
+
+