From 5702ea400bdc55d5ccddd6e35a16c13a8d5ee2b8 Mon Sep 17 00:00:00 2001 From: "github-classroom[bot]" <66690702+github-classroom[bot]@users.noreply.github.com> Date: Sun, 13 Aug 2023 14:51:29 +0000 Subject: [PATCH 01/17] Setting up GitHub Classroom Feedback From adb52186640f43553fb4dda4d15f6ce6b906aa6b Mon Sep 17 00:00:00 2001 From: QuantaQualia Date: Sun, 13 Aug 2023 13:35:07 -0500 Subject: [PATCH 02/17] alert added --- script.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/script.js b/script.js index 80569e3..f1d6a01 100644 --- a/script.js +++ b/script.js @@ -1,4 +1,16 @@ // Write your JavaScript code here! +window.addEventListener("load", function(){ +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 === "" || fuelLevelInput === "" || cargoMassInput == "") { + alert("All fields are required!"); + } + }); +}); window.addEventListener("load", function() { From 35ae04d3d87e7c6a9e8c02413f3967f26ab0f9aa Mon Sep 17 00:00:00 2001 From: QuantaQualia Date: Sun, 13 Aug 2023 16:28:23 -0500 Subject: [PATCH 03/17] started validateInput --- index.html | 2 +- script.js | 13 ++++++++++++- scriptHelper.js | 12 +++++++++--- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/index.html b/index.html index 8d93c57..8e18042 100644 --- a/index.html +++ b/index.html @@ -15,7 +15,7 @@

Launch Checklist Form

- +
diff --git a/script.js b/script.js index f1d6a01..d01943d 100644 --- a/script.js +++ b/script.js @@ -1,6 +1,6 @@ // Write your JavaScript code here! window.addEventListener("load", function(){ -let form = document.querySelector("form"); + let form = document.querySelector("form"); form.addEventListener("submit", function(event) { let pilotNameInput = document.querySelector("input[name=pilotName]"); let copilotNameInput = document.querySelector("input[name=copilotName]"); @@ -12,6 +12,17 @@ let form = document.querySelector("form"); }); }); +window.addEventListener("load", function() { + let form = document.querySelector("form"); + form.addEventListener("submit", function(event) { + let list; + let pilot = document.querySelector("input[name=pilotName]"); + let copilot = document.querySelector("input[name=copilotName]"); + let fuelLevel = document.querySelector("input[name=fuelLevel]"); + let cargoLevel = document.querySelector("input[name=pilotName]"); + }); +}); + window.addEventListener("load", function() { let listedPlanets; diff --git a/scriptHelper.js b/scriptHelper.js index 132331f..56c4c48 100644 --- a/scriptHelper.js +++ b/scriptHelper.js @@ -17,11 +17,17 @@ function addDestinationInfo(document, name, diameter, star, distance, moons, ima } function validateInput(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) { - + } async function myFetch() { From e88f416132db6b6c5112ad26d1d9527d9e67108f Mon Sep 17 00:00:00 2001 From: QuantaQualia Date: Sun, 13 Aug 2023 20:38:35 -0500 Subject: [PATCH 04/17] commit --- script.js | 1 + scriptHelper.js | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/script.js b/script.js index d01943d..a28124a 100644 --- a/script.js +++ b/script.js @@ -8,6 +8,7 @@ window.addEventListener("load", function(){ let cargoMassInput = document.querySelector("input[name=cargoMass]"); if (pilotNameInput.value === "" || copilotNameInput === "" || fuelLevelInput === "" || cargoMassInput == "") { alert("All fields are required!"); + event.preventDefault(); } }); }); diff --git a/scriptHelper.js b/scriptHelper.js index 56c4c48..1fe18f5 100644 --- a/scriptHelper.js +++ b/scriptHelper.js @@ -27,7 +27,7 @@ function validateInput(testInput) { }; function formSubmission(document, list, pilot, copilot, fuelLevel, cargoLevel) { - + } async function myFetch() { From 26cc5fcb40387bd4145ccc9c3fc57479071f8009 Mon Sep 17 00:00:00 2001 From: QuantaQualia Date: Sun, 13 Aug 2023 21:11:31 -0500 Subject: [PATCH 05/17] fixed first alert --- script.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/script.js b/script.js index a28124a..c735c8d 100644 --- a/script.js +++ b/script.js @@ -6,7 +6,7 @@ window.addEventListener("load", function(){ 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 === "" || fuelLevelInput === "" || cargoMassInput == "") { + if (pilotNameInput.value.trim() === "" || copilotNameInput.value.trim() === "" || fuelLevelInput.value.trim() === "" || cargoMassInput.value.trim() == "") { alert("All fields are required!"); event.preventDefault(); } From 7d9fc30a9250f32c6b308bd106143a1a94b0f89b Mon Sep 17 00:00:00 2001 From: QuantaQualia Date: Sun, 13 Aug 2023 21:39:39 -0500 Subject: [PATCH 06/17] started formSubmission --- scriptHelper.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/scriptHelper.js b/scriptHelper.js index 1fe18f5..84cbab5 100644 --- a/scriptHelper.js +++ b/scriptHelper.js @@ -17,7 +17,7 @@ function addDestinationInfo(document, name, diameter, star, distance, moons, ima } function validateInput(testInput) { - if (testInput = "") { + if (testInput.trim() = "") { return ("Empty"); } else if (isNaN(testInput)) { return ("Not a Number"); @@ -27,7 +27,15 @@ function validateInput(testInput) { }; function formSubmission(document, list, pilot, copilot, fuelLevel, cargoLevel) { - + if (validateInput(pilot) || validateInput(copilot) === "Empty" || "Is a Number"){ + alert("The Pilot and Copilot Must Be Specified With Valid Names"); + event.preventDefault(); + } + if (validateInput(fuelLevel) || validateInput(cargoLevel) === "Empty" || "Not a Number") { + alert("The Fuel Level and Cargo Mass Must Be Specified With Numerical Values") + event.preventDefault(); + } + } async function myFetch() { From efcd9287a35a96a35f48be0a50504ce7c447d23a Mon Sep 17 00:00:00 2001 From: QuantaQualia Date: Mon, 14 Aug 2023 01:07:00 -0500 Subject: [PATCH 07/17] working alerts --- script.js | 17 +++++------------ scriptHelper.js | 19 +++++++------------ 2 files changed, 12 insertions(+), 24 deletions(-) diff --git a/script.js b/script.js index c735c8d..4e85b25 100644 --- a/script.js +++ b/script.js @@ -1,28 +1,21 @@ // Write your JavaScript code here! -window.addEventListener("load", function(){ +window.addEventListener("load", function() { 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.trim() === "" || copilotNameInput.value.trim() === "" || fuelLevelInput.value.trim() === "" || cargoMassInput.value.trim() == "") { + if (validateInput(pilotNameInput.value, copilotNameInput.value, fuelLevelInput.value, cargoMassInput.value) == "Empty"){ alert("All fields are required!"); event.preventDefault(); + } else if (validateInput(pilotNameInput.value, copilotNameInput.valude) == "Is a Number" || validateInput(fuelLevelInput.value, cargoMassInput.value) == "Not a Number") { + alert("Make sure to enter valid information for each field!"); + event.preventDefault(); } }); }); -window.addEventListener("load", function() { - let form = document.querySelector("form"); - form.addEventListener("submit", function(event) { - let list; - let pilot = document.querySelector("input[name=pilotName]"); - let copilot = document.querySelector("input[name=copilotName]"); - let fuelLevel = document.querySelector("input[name=fuelLevel]"); - let cargoLevel = document.querySelector("input[name=pilotName]"); - }); -}); window.addEventListener("load", function() { diff --git a/scriptHelper.js b/scriptHelper.js index 84cbab5..b7d279d 100644 --- a/scriptHelper.js +++ b/scriptHelper.js @@ -17,26 +17,21 @@ function addDestinationInfo(document, name, diameter, star, distance, moons, ima } function validateInput(testInput) { - if (testInput.trim() = "") { + if (testInput.trim() == "") { return ("Empty"); - } else if (isNaN(testInput)) { + } else if (isNaN(testInput.trim())) { return ("Not a Number"); - } else if (!isNaN(testInput)) { + } else if (!isNaN(testInput.trim())) { return ("Is a Number"); } }; + + + function formSubmission(document, list, pilot, copilot, fuelLevel, cargoLevel) { - if (validateInput(pilot) || validateInput(copilot) === "Empty" || "Is a Number"){ - alert("The Pilot and Copilot Must Be Specified With Valid Names"); - event.preventDefault(); - } - if (validateInput(fuelLevel) || validateInput(cargoLevel) === "Empty" || "Not a Number") { - alert("The Fuel Level and Cargo Mass Must Be Specified With Numerical Values") - event.preventDefault(); - } -} +}; async function myFetch() { let planetsReturned; From 159bfa971dd3739af2c552f5ab25e3108771b499 Mon Sep 17 00:00:00 2001 From: QuantaQualia Date: Mon, 14 Aug 2023 02:26:49 -0500 Subject: [PATCH 08/17] commit --- script.js | 1 + scriptHelper.js | 1 + 2 files changed, 2 insertions(+) diff --git a/script.js b/script.js index 4e85b25..88c10df 100644 --- a/script.js +++ b/script.js @@ -14,6 +14,7 @@ window.addEventListener("load", function() { event.preventDefault(); } }); + formSubmission (window.document, list, pilotNameInput.value, copilotNameInput.value, fuelLevelInput.value, cargoMassInput.value); }); diff --git a/scriptHelper.js b/scriptHelper.js index b7d279d..f56cabb 100644 --- a/scriptHelper.js +++ b/scriptHelper.js @@ -31,6 +31,7 @@ function validateInput(testInput) { function formSubmission(document, list, pilot, copilot, fuelLevel, cargoLevel) { + }; async function myFetch() { From 3f97c457f1f74df5fb425b0db652572412a4cb0e Mon Sep 17 00:00:00 2001 From: QuantaQualia Date: Mon, 14 Aug 2023 05:58:42 -0500 Subject: [PATCH 09/17] commit --- script.js | 4 +++- scriptHelper.js | 6 ++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/script.js b/script.js index 88c10df..0890270 100644 --- a/script.js +++ b/script.js @@ -2,6 +2,7 @@ window.addEventListener("load", function() { let form = document.querySelector("form"); form.addEventListener("submit", function(event) { + let list = document.getElementById("faultyItems"); let pilotNameInput = document.querySelector("input[name=pilotName]"); let copilotNameInput = document.querySelector("input[name=copilotName]"); let fuelLevelInput = document.querySelector("input[name=fuelLevel]"); @@ -13,8 +14,9 @@ window.addEventListener("load", function() { alert("Make sure to enter valid information for each field!"); event.preventDefault(); } + formSubmission (window.document, list, pilotNameInput.value, copilotNameInput.value, fuelLevelInput.value, cargoMassInput.value); }); - formSubmission (window.document, list, pilotNameInput.value, copilotNameInput.value, fuelLevelInput.value, cargoMassInput.value); + }); diff --git a/scriptHelper.js b/scriptHelper.js index f56cabb..e6ff76a 100644 --- a/scriptHelper.js +++ b/scriptHelper.js @@ -27,9 +27,11 @@ function validateInput(testInput) { }; - - function formSubmission(document, list, pilot, copilot, fuelLevel, cargoLevel) { + pilotStatus.innerHTML = `Pilot ${pilot} is ready for launch`; + copilotStatus.innerHTML = `Copilot ${copilot} is ready for launch`; + + }; From 0a75af1c23ef23bd19bfc6f0451caa3e38452f35 Mon Sep 17 00:00:00 2001 From: QuantaQualia Date: Mon, 14 Aug 2023 20:38:07 -0500 Subject: [PATCH 10/17] formsubmission --- script.js | 20 +++++++++++--------- scriptHelper.js | 32 +++++++++++++++++++++++++++----- 2 files changed, 38 insertions(+), 14 deletions(-) diff --git a/script.js b/script.js index 0890270..20cef39 100644 --- a/script.js +++ b/script.js @@ -2,19 +2,21 @@ window.addEventListener("load", function() { let form = document.querySelector("form"); form.addEventListener("submit", function(event) { + let list = document.getElementById("faultyItems"); - 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 (validateInput(pilotNameInput.value, copilotNameInput.value, fuelLevelInput.value, cargoMassInput.value) == "Empty"){ + let pilotNameInput = document.querySelector("input[name=pilotName]").value; + let copilotNameInput = document.querySelector("input[name=copilotName]").value; + let fuelLevelInput = document.querySelector("input[name=fuelLevel]").value; + let cargoMassInput = document.querySelector("input[name=cargoMass]").value; + event.preventDefault(); + if (validateInput(pilotNameInput) === "Empty" || validateInput(copilotNameInput) === "Empty" || validateInput(fuelLevelInput) === "Empty" || validateInput(cargoMassInput) === "Empty") { alert("All fields are required!"); - event.preventDefault(); - } else if (validateInput(pilotNameInput.value, copilotNameInput.valude) == "Is a Number" || validateInput(fuelLevelInput.value, cargoMassInput.value) == "Not a Number") { + + } else if (validateInput(pilotNameInput) == "Is a Number" || validateInput(copilotNameInput) == "Is a Number" || validateInput(fuelLevelInput) == "Not a Number" || validateInput(fuelLevelInput) == "Not a Number") { alert("Make sure to enter valid information for each field!"); - event.preventDefault(); + } - formSubmission (window.document, list, pilotNameInput.value, copilotNameInput.value, fuelLevelInput.value, cargoMassInput.value); + formSubmission (document, list, pilotNameInput, copilotNameInput, fuelLevelInput, cargoMassInput); }); }); diff --git a/scriptHelper.js b/scriptHelper.js index e6ff76a..c043a51 100644 --- a/scriptHelper.js +++ b/scriptHelper.js @@ -14,7 +14,7 @@ function addDestinationInfo(document, name, diameter, star, distance, moons, ima */ -} +}; function validateInput(testInput) { if (testInput.trim() == "") { @@ -28,12 +28,34 @@ function validateInput(testInput) { function formSubmission(document, list, pilot, copilot, fuelLevel, cargoLevel) { - pilotStatus.innerHTML = `Pilot ${pilot} is ready for launch`; - copilotStatus.innerHTML = `Copilot ${copilot} is ready for launch`; - + console.log(pilot); + document.getElementById("pilotStatus").innerHTML = `Pilot ${pilot} is ready for launch`; + document.getElementById("copilotStatus").innerHTML = `Copilot ${copilot} is ready for launch`; + + if ((fuelLevel < 10000) && (cargoLevel <= 10000)) { + document.getElementById("fuelStatus").innerHTML = `Fuel level too low for launch`; + document.getElementById("cargoStatus").innerHTML = `Cargo mass low enough for launch`; + document.getElementById("faultyItems").style.visibility = "visible"; + document.getElementById("launchStatusCheck").style.color = "#C7254E"; + + } else if ((fuelLevel >= 10000) && (cargoLevel > 10000)) { + document.getElementById("fuelStatus").innerHTML = `Fuel level high enough for launch` + document.getElementById("cargoStatus").innerHTML = `Cargo mass too heavy for launch`; + document.getElementById("faultyItems").style.visibility = "visible"; + document.getElementById("launchStatusCheck").style.color = "#C7254E"; + + } else if ((fuelLevel < 10000) && (cargoLevel > 10000) ) { + document.getElementById("fuelStatus").innerHTML = `Fuel level too low for launch`; + document.getElementById("cargoStatus").innerHTML = `Cargo mass too heavy for launch`; + document.getElementById("faultyItems").style.visibility = "visible"; + document.getElementById("launchStatusCheck").style.color = "#C7254E"; + + } else if ((fuelLevel >= 10000) && (cargoLevel <= 10000)) { + document.getElementById("faultyItems").style.visibility = "visible"; + document.getElementById("launchStatusCheck").style.color = "#419F6A"; + }; - }; async function myFetch() { From 99671ebd698161878f7dd15e6af29b62111ee00e Mon Sep 17 00:00:00 2001 From: QuantaQualia Date: Tue, 15 Aug 2023 00:31:04 -0500 Subject: [PATCH 11/17] fetch work --- scriptHelper.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/scriptHelper.js b/scriptHelper.js index c043a51..5f76993 100644 --- a/scriptHelper.js +++ b/scriptHelper.js @@ -53,7 +53,11 @@ function formSubmission(document, list, pilot, copilot, fuelLevel, cargoLevel) { } else if ((fuelLevel >= 10000) && (cargoLevel <= 10000)) { document.getElementById("faultyItems").style.visibility = "visible"; + document.getElementById("launchStatus").innerHTML = `Shuttle is Ready for Launch`; document.getElementById("launchStatusCheck").style.color = "#419F6A"; + document.getElementById("fuelStatus").innerHTML = `Fuel level high enough for launch`; + document.getElementById("cargoStatus").innerHTML = `Cargo mass low enough for launch`; + }; }; @@ -61,13 +65,18 @@ function formSubmission(document, list, pilot, copilot, fuelLevel, cargoLevel) { async function myFetch() { let planetsReturned; - planetsReturned = await fetch().then( function(response) { + planetsReturned = await fetch("https://handlers.education.launchcode.org/static/planets.json").then( function(response) { + let planetsPromise = response.json(); + planetsPromise.then( function(json) { }); return planetsReturned; -} + }); +}; function pickPlanet(planets) { + let planetPicked = planets[Math.floor(Math.random()*planets.length)]; + return planetPicked; } module.exports.addDestinationInfo = addDestinationInfo; From 03e780b118f26c86a89aa16c58d3910993bac737 Mon Sep 17 00:00:00 2001 From: QuantaQualia Date: Tue, 15 Aug 2023 20:10:43 -0500 Subject: [PATCH 12/17] myFetch work --- script.js | 2 +- scriptHelper.js | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/script.js b/script.js index 20cef39..43b9fa7 100644 --- a/script.js +++ b/script.js @@ -26,7 +26,7 @@ window.addEventListener("load", function() { let listedPlanets; // Set listedPlanetsResponse equal to the value returned by calling myFetch() - let listedPlanetsResponse; + let listedPlanetsResponse = myFetch(); listedPlanetsResponse.then(function (result) { listedPlanets = result; console.log(listedPlanets); diff --git a/scriptHelper.js b/scriptHelper.js index 5f76993..ee17679 100644 --- a/scriptHelper.js +++ b/scriptHelper.js @@ -68,6 +68,7 @@ async function myFetch() { planetsReturned = await fetch("https://handlers.education.launchcode.org/static/planets.json").then( function(response) { let planetsPromise = response.json(); planetsPromise.then( function(json) { + console.log(planetsPromise); }); return planetsReturned; From a690e0ba515566a86ee9691ada13942af5f0953c Mon Sep 17 00:00:00 2001 From: QuantaQualia Date: Tue, 15 Aug 2023 22:04:36 -0500 Subject: [PATCH 13/17] pickPlanet working --- script.js | 8 +++++--- scriptHelper.js | 8 +++++++- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/script.js b/script.js index 43b9fa7..7573a2a 100644 --- a/script.js +++ b/script.js @@ -15,8 +15,9 @@ window.addEventListener("load", function() { } else if (validateInput(pilotNameInput) == "Is a Number" || validateInput(copilotNameInput) == "Is a Number" || validateInput(fuelLevelInput) == "Not a Number" || validateInput(fuelLevelInput) == "Not a Number") { alert("Make sure to enter valid information for each field!"); - } + } else { formSubmission (document, list, pilotNameInput, copilotNameInput, fuelLevelInput, cargoMassInput); + } }); }); @@ -29,10 +30,11 @@ window.addEventListener("load", function() { let listedPlanetsResponse = myFetch(); listedPlanetsResponse.then(function (result) { listedPlanets = result; - console.log(listedPlanets); }).then(function () { - console.log(listedPlanets); // Below this comment call the appropriate helper functions to pick a planet fom the list of planets and add that information to your destination. + //console.log(pickPlanet(listedPlanets)); + let planetPicked = pickPlanet(listedPlanets); + console.log(planetPicked); }) }); \ No newline at end of file diff --git a/scriptHelper.js b/scriptHelper.js index ee17679..b5070ea 100644 --- a/scriptHelper.js +++ b/scriptHelper.js @@ -14,6 +14,8 @@ function addDestinationInfo(document, name, diameter, star, distance, moons, ima */ + + }; function validateInput(testInput) { @@ -36,18 +38,21 @@ function formSubmission(document, list, pilot, copilot, fuelLevel, cargoLevel) { if ((fuelLevel < 10000) && (cargoLevel <= 10000)) { document.getElementById("fuelStatus").innerHTML = `Fuel level too low for launch`; document.getElementById("cargoStatus").innerHTML = `Cargo mass low enough for launch`; + document.getElementById("launchStatus").innerHTML = `Shuttle Not Ready for Launch`; document.getElementById("faultyItems").style.visibility = "visible"; document.getElementById("launchStatusCheck").style.color = "#C7254E"; } else if ((fuelLevel >= 10000) && (cargoLevel > 10000)) { document.getElementById("fuelStatus").innerHTML = `Fuel level high enough for launch` document.getElementById("cargoStatus").innerHTML = `Cargo mass too heavy for launch`; + document.getElementById("launchStatus").innerHTML = `Shuttle Not Ready for Launch`; document.getElementById("faultyItems").style.visibility = "visible"; document.getElementById("launchStatusCheck").style.color = "#C7254E"; } else if ((fuelLevel < 10000) && (cargoLevel > 10000) ) { document.getElementById("fuelStatus").innerHTML = `Fuel level too low for launch`; document.getElementById("cargoStatus").innerHTML = `Cargo mass too heavy for launch`; + document.getElementById("launchStatus").innerHTML = `Shuttle Not Ready for Launch`; document.getElementById("faultyItems").style.visibility = "visible"; document.getElementById("launchStatusCheck").style.color = "#C7254E"; @@ -76,7 +81,8 @@ async function myFetch() { }; function pickPlanet(planets) { - let planetPicked = planets[Math.floor(Math.random()*planets.length)]; + planets = 7; + let planetPicked = Math.floor(Math.random()*planets); return planetPicked; } From ded7cbbf59bab1720a18f29e50678aa788d1b5be Mon Sep 17 00:00:00 2001 From: QuantaQualia Date: Wed, 16 Aug 2023 18:00:15 -0500 Subject: [PATCH 14/17] commit for TA review --- script.js | 14 +++++++------- scriptHelper.js | 12 +++++------- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/script.js b/script.js index 7573a2a..4432bac 100644 --- a/script.js +++ b/script.js @@ -24,17 +24,17 @@ window.addEventListener("load", function() { window.addEventListener("load", function() { - - let listedPlanets; + let listedPlanets; // Set listedPlanetsResponse equal to the value returned by calling myFetch() - let listedPlanetsResponse = myFetch(); + let listedPlanetsResponse; + listedPlanetsResponse = myFetch(); listedPlanetsResponse.then(function (result) { - listedPlanets = result; + listedPlanets = result; + console.log(listedPlanets); }).then(function () { + console.log(listedPlanets); // Below this comment call the appropriate helper functions to pick a planet fom the list of planets and add that information to your destination. - //console.log(pickPlanet(listedPlanets)); let planetPicked = pickPlanet(listedPlanets); console.log(planetPicked); - }) - +}) }); \ No newline at end of file diff --git a/scriptHelper.js b/scriptHelper.js index b5070ea..f14d69c 100644 --- a/scriptHelper.js +++ b/scriptHelper.js @@ -15,7 +15,7 @@ function addDestinationInfo(document, name, diameter, star, distance, moons, ima */ - + }; function validateInput(testInput) { @@ -69,21 +69,19 @@ function formSubmission(document, list, pilot, copilot, fuelLevel, cargoLevel) { async function myFetch() { let planetsReturned; - + let planetsPromise; planetsReturned = await fetch("https://handlers.education.launchcode.org/static/planets.json").then( function(response) { - let planetsPromise = response.json(); + planetsPromise = response.json(); planetsPromise.then( function(json) { console.log(planetsPromise); }); - - return planetsReturned; }); }; function pickPlanet(planets) { - planets = 7; - let planetPicked = Math.floor(Math.random()*planets); + let planetPicked = Math.floor(Math.random()*planets.length); return planetPicked; + } module.exports.addDestinationInfo = addDestinationInfo; From 874fd50d8d465fe40636d3d32145157d51993478 Mon Sep 17 00:00:00 2001 From: QuantaQualia Date: Thu, 17 Aug 2023 10:00:44 -0500 Subject: [PATCH 15/17] fixed listedPlanets scope --- script.js | 28 ++++++++++++++-------------- scriptHelper.js | 15 ++++++--------- 2 files changed, 20 insertions(+), 23 deletions(-) diff --git a/script.js b/script.js index 4432bac..01711b0 100644 --- a/script.js +++ b/script.js @@ -24,17 +24,17 @@ window.addEventListener("load", function() { window.addEventListener("load", function() { - let listedPlanets; - // Set listedPlanetsResponse equal to the value returned by calling myFetch() - let listedPlanetsResponse; - listedPlanetsResponse = myFetch(); - listedPlanetsResponse.then(function (result) { - listedPlanets = result; - console.log(listedPlanets); - }).then(function () { - console.log(listedPlanets); - // Below this comment call the appropriate helper functions to pick a planet fom the list of planets and add that information to your destination. - let planetPicked = pickPlanet(listedPlanets); - console.log(planetPicked); -}) -}); \ No newline at end of file + + let listedPlanetsResponse = myFetch(); + listedPlanetsResponse.then(function (result) { + listedPlanets = result; + console.log(listedPlanets); + }).then(function () { + console.log(listedPlanets); + // Below this comment call the appropriate helper functions to pick a planet fom the list of planets and add that information to your destination. + planetPicked = pickPlanet(listedPlanets); + console.log(planetPicked); + }) + +}); + diff --git a/scriptHelper.js b/scriptHelper.js index f14d69c..402752f 100644 --- a/scriptHelper.js +++ b/scriptHelper.js @@ -68,18 +68,15 @@ function formSubmission(document, list, pilot, copilot, fuelLevel, cargoLevel) { }; async function myFetch() { - let planetsReturned; - let planetsPromise; - planetsReturned = await fetch("https://handlers.education.launchcode.org/static/planets.json").then( function(response) { - planetsPromise = response.json(); - planetsPromise.then( function(json) { - console.log(planetsPromise); - }); - }); + + let response = await fetch("https://handlers.education.launchcode.org/static/planets.json"); + let json = await response.json(); + return json; }; function pickPlanet(planets) { - let planetPicked = Math.floor(Math.random()*planets.length); + let planetPicked; + planetPicked = planets[Math.floor(Math.random()*planets.length)]; return planetPicked; } From 2278f95f23de918cbec994a03a5be3d95821393e Mon Sep 17 00:00:00 2001 From: QuantaQualia Date: Thu, 17 Aug 2023 13:21:56 -0500 Subject: [PATCH 16/17] addDestination working --- script.js | 1 + scriptHelper.js | 20 +++++++++++++++++--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/script.js b/script.js index 01711b0..37df26c 100644 --- a/script.js +++ b/script.js @@ -34,6 +34,7 @@ window.addEventListener("load", function() { // Below this comment call the appropriate helper functions to pick a planet fom the list of planets and add that information to your destination. planetPicked = pickPlanet(listedPlanets); console.log(planetPicked); + destination = addDestinationInfo(document, planetPicked.name, planetPicked.diameter, planetPicked.star, planetPicked.distance, planetPicked.moons, planetPicked.image); }) }); diff --git a/scriptHelper.js b/scriptHelper.js index 402752f..2101d09 100644 --- a/scriptHelper.js +++ b/scriptHelper.js @@ -1,7 +1,6 @@ -// Write your helper functions here! require('isomorphic-fetch'); -function addDestinationInfo(document, name, diameter, star, distance, moons, imageUrl) { +function addDestinationInfo(document, name, diameter, star, distance, moons, imageURL) { // Here is the HTML formatting for our mission target div. /*

Mission Destination

@@ -14,8 +13,23 @@ function addDestinationInfo(document, name, diameter, star, distance, moons, ima */ + - + let destination = document.getElementById("missionTarget"); + + destination.innerHTML += `

Mission Destination

+
    +
  1. Name: ${name}
  2. +
  3. Diameter: ${diameter}
  4. +
  5. Star: ${star}
  6. +
  7. Distance from Earth: ${distance}
  8. +
  9. Number of Moons: ${moons}
  10. +
+ `; + + console.log(destination); + + }; function validateInput(testInput) { From 772cff58cb20fefeb948962b8b691b174bf00e27 Mon Sep 17 00:00:00 2001 From: QuantaQualia Date: Thu, 17 Aug 2023 13:57:04 -0500 Subject: [PATCH 17/17] co-pilot vs copilot --- scriptHelper.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scriptHelper.js b/scriptHelper.js index 2101d09..bf2fa9f 100644 --- a/scriptHelper.js +++ b/scriptHelper.js @@ -46,7 +46,7 @@ function validateInput(testInput) { function formSubmission(document, list, pilot, copilot, fuelLevel, cargoLevel) { console.log(pilot); document.getElementById("pilotStatus").innerHTML = `Pilot ${pilot} is ready for launch`; - document.getElementById("copilotStatus").innerHTML = `Copilot ${copilot} is ready for launch`; + document.getElementById("copilotStatus").innerHTML = `Co-pilot ${copilot} is ready for launch`; if ((fuelLevel < 10000) && (cargoLevel <= 10000)) {