diff --git a/booleans-and-conditionals/exercises/part-1.js b/booleans-and-conditionals/exercises/part-1.js index b829140a07..f4633a415b 100644 --- a/booleans-and-conditionals/exercises/part-1.js +++ b/booleans-and-conditionals/exercises/part-1.js @@ -1,11 +1,16 @@ // Declare and initialize the variables for exercise 1 here: - +let engineIndicatorLight = "red blinking"; +let spaceSuitsOn = true; +let shuttleCabinReady = true; +let crewStatus = spaceSuitsOn && shuttleCabinReady; +let computerStatusCode = 200; +let shuttleSpeed = 15000; // BEFORE running the code, predict what will be printed to the console by the following statements: if (engineIndicatorLight === "green") { - console.log("engines have started"); + console.log("engines have started"); } else if (engineIndicatorLight === "green blinking") { - console.log("engines are preparing to start"); + console.log("engines are preparing to start"); } else { - console.log("engines are off"); + console.log("engines are off"); } diff --git a/booleans-and-conditionals/exercises/part-2.js b/booleans-and-conditionals/exercises/part-2.js index ff11fbab8a..ed3399c355 100644 --- a/booleans-and-conditionals/exercises/part-2.js +++ b/booleans-and-conditionals/exercises/part-2.js @@ -8,14 +8,29 @@ let shuttleSpeed = 15000; // 3) Write conditional expressions to satisfy the following safety rules: // a) If crewStatus is true, print "Crew Ready" else print "Crew Not Ready". - +if (crewStatus) { + console.log("Crew Ready"); +} else { + console.log("Crew Not Ready"); +} // b) If computerStatusCode is 200, print "Please stand by. Computer is rebooting." Else if computerStatusCode is 400, print "Success! Computer online." Else print "ALERT: Computer offline!" - +if (computerStatusCode === 200) { + console.log("Please stand by. Computer is rebooting."); +} else if (computerStatusCode === 400) { + console.log("Success! Computer online."); +} else { + console.log("ALERT: Computer offline!"); +} // c) If shuttleSpeed is > 17,500, print "ALERT: Escape velocity reached!" Else if shuttleSpeed is < 8000, print "ALERT: Cannot maintain orbit!" Else print "Stable speed". - - +if (shuttleSpeed > 17500) { + console.log("ALERT: Escape velocity reached!"); +} else if (shuttleSpeed < 8000) { + console.log("ALERT: Cannot maintain orbit!"); +} else { + console.log("Stable speed."); +} // 4) PREDICT: Do the code blocks shown in the 'predict.txt' file produce the same result? -console.log(/* "Yes" or "No" */); +console.log("Yes"); diff --git a/booleans-and-conditionals/exercises/part-3.js b/booleans-and-conditionals/exercises/part-3.js index 9ed686d097..d361090234 100644 --- a/booleans-and-conditionals/exercises/part-3.js +++ b/booleans-and-conditionals/exercises/part-3.js @@ -1,7 +1,25 @@ -let engineIndicatorLight = 'red blinking'; +let engineIndicatorLight = "red blinking"; let fuelLevel = 21000; let engineTemperature = 1200; +if ( + fuelLevel < 1000 || + engineTemperature > 3500 || + engineIndicatorLight === "red blinking" +) { + console.log("ENGINE FAILURE IMMINENT!"); +} else if (fuelLevel <= 5000 || engineTemperature > 2500) { + console.log("Check fuel level. Engines running hot."); +} else if (fuelLevel > 20000 && engineTemperature <= 2500) { + console.log("Full tank. Engines good."); +} else if (fuelLevel > 10000 && engineTemperature <= 2500) { + console.log("Fuel level above 50%. Engines good."); +} else if (fuelLevel > 5000 && engineTemperature <= 2500) { + console.log("Fuel level above 25%. Engines good."); +} else { + console.log("Fuel and engine status pending..."); +} + /* 5) Implement the following checks using if/else if/else statements: a) If fuelLevel is above 20000 AND engineTemperature is at or below 2500, print "Full tank. Engines good." @@ -22,3 +40,9 @@ f) Otherwise, print "Fuel and engine status pending..." */ /* 6) b) Code the following if/else check: If fuelLevel is above 20000 AND engineIndicatorLight is NOT red blinking OR commandOverride is true print "Cleared to launch!" Else print "Launch scrubbed!" */ +let commandOverride = true; +if ((fuelLevel > 20000 && engineIndicatorLight !== 'red blinking') || commandOverride) { + console.log("Cleared to launch"); +} else { + console.log("Launch scrubbed!"); +} \ No newline at end of file diff --git a/booleans-and-conditionals/studio/data-variables-conditionals.js b/booleans-and-conditionals/studio/data-variables-conditionals.js index 6a15e146f4..8adaf8214e 100644 --- a/booleans-and-conditionals/studio/data-variables-conditionals.js +++ b/booleans-and-conditionals/studio/data-variables-conditionals.js @@ -1,15 +1,68 @@ // Initialize Variables below +let date = "Monday 2019-03-18"; +let time = "10:05:34 AM"; +let astronautCount = 7; +let astronautStatus = "ready"; +let averageAstronautMassKg = 80.7; +let crewMassKg = astronautCount * averageAstronautMassKg; +let fuelMassKg = 760000; +let shuttleMassKg = 74842.31; +let totalMassKg = crewMassKg + fuelMassKg + shuttleMassKg; +let maximumMassLimit = 850000; +let fuelTempCelsius = -225; +let minimumFuelTemp = -300; +let maximumFuelTemp = -150; +let fuelLevel = "100%"; +let weatherStatus = "clear"; +let prepareForLiftOff = true; // add logic below to verify total number of astronauts for shuttle launch does not exceed 7 - +let isClearedForLiftOff = true; +if (astronautCount > 7) { + isClearedForLiftOff = false; + console.log("Astronaut count exceeds limit."); +} // add logic below to verify all astronauts are ready - +if (astronautStatus !== "ready") { + isClearedForLiftOff = false; + console.log("Astronaut status not ready"); +} // add logic below to verify the total mass does not exceed the maximum limit of 850000 +if (totalMassKg >= maximumMassLimit) { + isClearedForLiftOff = false; + console.log("Total mass exceeds maximum mass limit."); +} // add logic below to verify the fuel temperature is within the appropriate range of -150 and -300 +if (fuelTempCelsius < minimumFuelTemp || fuelTempCelsius > maximumFuelTemp) { + isClearedForLiftOff = false; + console.log("Fuel temperature out of acceptable range."); +} // add logic below to verify the fuel level is at 100% +if (fuelLevel !== "100%") { + isClearedForLiftOff = false; + console.log("Fuel level not at 100%."); +} // add logic below to verify the weather status is clear - +if (weatherStatus !== "clear") { + isClearedForLiftOff = false; + console.log("Weather status not clear."); +} // Verify shuttle launch can proceed based on above conditions +if (isClearedForLiftOff && prepareForLiftOff) { + console.log("All systems are a go! Initiating space shuttle launch sequence."); + console.log("Date:", date); + console.log("Time:", time); + console.log("Astronaut Count:", astronautCount); + console.log("Crew Mass (kg):", crewMassKg); + console.log("Fuel mass (kg):", fuelMassKg); + console.log("Shuttle Mass (kg):", shuttleMassKg); + console.log("Total Mass (kg):", totalMassKg); + console.log("Fuel Temperatture (Celsius):", fuelTempCelsius); + console.log("Weather Status:", weatherStatus); + console.log("Have a safe trip astronauts!"); +} else { + console.log("Launch operations aborted."); +} diff --git a/data-and-variables/exercises/data-and-variables-exercises.js b/data-and-variables/exercises/data-and-variables-exercises.js index 6433bcd641..af28bab328 100644 --- a/data-and-variables/exercises/data-and-variables-exercises.js +++ b/data-and-variables/exercises/data-and-variables-exercises.js @@ -1,11 +1,26 @@ // Declare and assign the variables below - +let shuttleName = "Determination"; +let shuttleSpeedMph = 17500; +let distanceToMarsKm = 225000000; +let distanceToMoonKm = 38400; +const milesPerKm = 0.621; // Use console.log to print the 'typeof' each variable. Print one item per line. - +console.log(typeof "Determination"); +console.log(typeof 17500); +console.log(typeof 225000000); +console.log(typeof 38400); +console.log(typeof 0.621); // Calculate a space mission below - +let milesToMars = distanceToMarsKm * milesPerKm; +let hoursToMars = milesToMars / shuttleSpeedMph; +let daysToMars = hoursToMars / 24; // Print the results of the space mission calculations below - +console.log(shuttleName + " will take " + daysToMars + " days to reach Mars."); // Calculate a trip to the moon below - -// Print the results of the trip to the moon below \ No newline at end of file +let milesToMoon = distanceToMoonKm * milesPerKm; +let hoursToMoon = milesToMoon / shuttleSpeedMph; +let daysToMoon = hoursToMoon / 24; +// Print the results of the trip to the moon below +console.log( + shuttleName + " will take " + daysToMoon + " days to reach the Moon." +); diff --git a/errors-and-debugging/chapter-examples/SyntaxErrors.js b/errors-and-debugging/chapter-examples/SyntaxErrors.js index 5597f22de5..8edaeaf279 100644 --- a/errors-and-debugging/chapter-examples/SyntaxErrors.js +++ b/errors-and-debugging/chapter-examples/SyntaxErrors.js @@ -1,2 +1,2 @@ let day = Wednesday; -console.log(day; \ No newline at end of file +console.log(day); \ No newline at end of file diff --git a/errors-and-debugging/exercises/Debugging1stSyntaxError.js b/errors-and-debugging/exercises/Debugging1stSyntaxError.js index 365af5a964..442bc86a6b 100644 --- a/errors-and-debugging/exercises/Debugging1stSyntaxError.js +++ b/errors-and-debugging/exercises/Debugging1stSyntaxError.js @@ -4,10 +4,10 @@ let launchReady = false; let fuelLevel = 17000; -if (fuelLevel >= 20000 { - console.log('Fuel level cleared.'); - launchReady = true; +if (fuelLevel >= 20000) { + console.log("Fuel level cleared."); + launchReady = true; } else { - console.log('WARNING: Insufficient fuel!'); - launchReady = false; -} \ No newline at end of file + console.log("WARNING: Insufficient fuel!"); + launchReady = false; +} diff --git a/errors-and-debugging/exercises/DebuggingLogicErrors5.js b/errors-and-debugging/exercises/DebuggingLogicErrors5.js index 7eb908e769..d37adac256 100644 --- a/errors-and-debugging/exercises/DebuggingLogicErrors5.js +++ b/errors-and-debugging/exercises/DebuggingLogicErrors5.js @@ -1,28 +1,39 @@ // The value of launchReady assigned in the first if/else block gets changed in the second if/else block. Dangerous waters... -// Since the issue is with launchReady, ONE way to fix the logic error is to use a different variable to store the fuel check result. +// Since the issue is with launchReady, ONE way to fix the logic error is to use a different variable to store the fuel check result. // Refactor the code to do this. Verify that your change works by updating the console.log statements. let launchReady = false; +crewReady = false; let fuelLevel = 17000; let crewStatus = true; -let computerStatus = 'green'; +let computerStatus = "green"; if (fuelLevel >= 20000) { - console.log('Fuel level cleared.'); - launchReady = true; + console.log("Fuel level cleared."); + launchReady = true; } else { - console.log('WARNING: Insufficient fuel!'); - launchReady = false; + console.log("WARNING: Insufficient fuel!"); + launchReady = false; } console.log("launchReady = ", launchReady); -if (crewStatus && computerStatus === 'green'){ - console.log('Crew & computer cleared.'); - launchReady = true; +if (crewStatus && computerStatus === "green") { + console.log("Crew & computer cleared."); + crewReady = true; } else { - console.log('WARNING: Crew or computer not ready!'); - launchReady = false; + console.log("WARNING: Crew or computer not ready!"); + crewReady = false; } -console.log("launchReady = ", launchReady); \ No newline at end of file +console.log("crewReady = ", crewReady); +// final if/else countdown +if (launchReady && crewReady) { + console.log("All systems go. Countdown to liftoff: "); + for (let i = 3; i > 0; i--) { + console.log(i); + } + console.log("Liftoff!"); +} else { + console.log("Launch scrubbed. "); +} diff --git a/errors-and-debugging/exercises/DebuggingRuntimeErrors1.js b/errors-and-debugging/exercises/DebuggingRuntimeErrors1.js index e66e494a30..7bbf7ebb82 100644 --- a/errors-and-debugging/exercises/DebuggingRuntimeErrors1.js +++ b/errors-and-debugging/exercises/DebuggingRuntimeErrors1.js @@ -4,7 +4,7 @@ let launchReady = false; let fuelLevel = 17000; -if (fuellevel >= 20000) { +if (fuelLevel >= 20000) { console.log('Fuel level cleared.'); launchReady = true; } else { diff --git a/errors-and-debugging/exercises/DebuggingRuntimeErrors2.js b/errors-and-debugging/exercises/DebuggingRuntimeErrors2.js index a656080d25..703a0d61c4 100644 --- a/errors-and-debugging/exercises/DebuggingRuntimeErrors2.js +++ b/errors-and-debugging/exercises/DebuggingRuntimeErrors2.js @@ -14,7 +14,7 @@ if (launchReady) { console.log("Fed parrot..."); console.log("6, 5, 4..."); console.log("Ignition..."); - consoul.log("3, 2, 1..."); + console.log("3, 2, 1..."); console.log("Liftoff!"); } else { console.log("Launch scrubbed."); diff --git a/errors-and-debugging/exercises/DebuggingSyntaxErrors2.js b/errors-and-debugging/exercises/DebuggingSyntaxErrors2.js index b600339254..947f0b33bb 100644 --- a/errors-and-debugging/exercises/DebuggingSyntaxErrors2.js +++ b/errors-and-debugging/exercises/DebuggingSyntaxErrors2.js @@ -1,26 +1,26 @@ //This block of code hides two syntax errors. -// Run the code and find the mistakes. -// Only ONE error will be flagged at a time. +// Run the code and find the mistakes. +// Only ONE error will be flagged at a time. // Fix that ONE problem, and then re-run the code to check yer work. Avoid trying to fix multiple issues at once. let launchReady = false; let crewStatus = true; -let computerStatus = 'green'; +let computerStatus = "green"; -if (crewStatus &&& computerStatus === 'green'){ - console.log('Crew & computer cleared.'); - launchReady = true; +if (crewStatus && computerStatus === "green") { + console.log("Crew & computer cleared."); + launchReady = true; } else { - console.log('WARNING: Crew or computer not ready!'); - launchReady = false; + console.log("WARNING: Crew or computer not ready!"); + launchReady = false; } if (launchReady) { - console.log(("10, 9, 8, 7, 6, 5, 4, 3, 2, 1..."); - console.log("Fed parrot..."); - console.log("Ignition..."); - console.log("Liftoff!"); + console.log("10, 9, 8, 7, 6, 5, 4, 3, 2, 1..."); + console.log("Fed parrot..."); + console.log("Ignition..."); + console.log("Liftoff!"); } else { - console.log("Launch scrubbed."); -} \ No newline at end of file + console.log("Launch scrubbed."); +} diff --git a/how-to-write-code/assignment0-javascript b/how-to-write-code/assignment0-javascript new file mode 160000 index 0000000000..e1be55f9af --- /dev/null +++ b/how-to-write-code/assignment0-javascript @@ -0,0 +1 @@ +Subproject commit e1be55f9af96fb792c10fdf77d217f8e6013c138 diff --git a/objects-and-math/exercises/ObjectExercises.js b/objects-and-math/exercises/ObjectExercises.js index 9a50cbdecc..14e15c17ce 100644 --- a/objects-and-math/exercises/ObjectExercises.js +++ b/objects-and-math/exercises/ObjectExercises.js @@ -1,24 +1,79 @@ let superChimpOne = { - name: "Chad", - species: "Chimpanzee", - mass: 9, - age: 6 + name: "Chad", + species: "Chimpanzee", + mass: 9, + age: 6, + astronautID: 1, + move: function () { + return Math.floor(Math.random() * 11); + }, }; let salamander = { - name: "Lacey", - species: "Axolotl Salamander", - mass: 0.1, - age: 5 + name: "Lacey", + species: "Axolotl Salamander", + mass: 0.1, + age: 5, + astronautID: 2, + move: function () { + return Math.floor(Math.random() * 11); + }, +}; +let superChimpTwo = { + name: "Brad", + species: "Chimpanzee", + mass: 11, + age: 6, + astronautID: 3, + move: function () { + return Math.floor(Math.random() * 11); + }, +}; +let dog = { + name: "Leroy", + species: "Beagle", + mass: 14, + age: 5, + astronautID: 4, + move: function () { + return Math.floor(Math.random() * 11); + }, +}; +let waterBear = { + name: "Almina", + species: "Tardigrade", + mass: 0.0000000001, + age: 1, + astronautID: 5, + move: function () { + return Math.floor(Math.random() * 11); + }, }; - // After you have created the other object literals, add the astronautID property to each one. // Add a move method to each animal object // Create an array to hold the animal objects. +let crew = [superChimpOne, superChimpTwo, salamander, dog, waterBear]; // Print out the relevant information about each animal. - +function crewReports(animal) { + return `${animal.name} is a ${animal.species}. They are ${animal.age} years old and ${animal.mass} kilograms. Their ID is ${animal.astronautID}.`; +} +crew.forEach((animal) => console.log(crewReports(animal))); // Start an animal race! +function fitnessTest(crew) { + let results = crew.map((animal) => { + let steps = 0; + let turns = 0; + while (steps < 20) { + steps += animal.move(); + turns++; + } + return `${animal.name} took ${turns} turns to take 20 steps.`; + }); + return results; +} +let raceResults = fitnessTest(crew); +raceResults.forEach((result) => console.log(result)); diff --git a/objects-and-math/studio/ObjectsStudio01.js b/objects-and-math/studio/ObjectsStudio01.js index 98dd0cd471..d40a0df6e2 100644 --- a/objects-and-math/studio/ObjectsStudio01.js +++ b/objects-and-math/studio/ObjectsStudio01.js @@ -1,55 +1,102 @@ // Code your selectRandomEntry function here: -// Code your buildCrewArray function here: - let idNumbers = [291, 414, 503, 599, 796, 890]; +function selectRandomEntry(arrayInput) { + return arrayInput[Math.floor(Math.random() * arrayInput.length)]; +} +const selectedArray = []; +while (selectedArray.length < 3) { + let randomNum = selectRandomEntry(idNumbers); + if (!(selectedArray.includes(randomNum))) { + selectedArray.push(randomNum); + + } +} + +// Code your buildCrewArray function here: +function buildCrewArray(selectedArray, animals) { + let crew = []; + for (let id of selectedArray) { + for (let animal of animals) { + if (animal.astronautID === id) { + crew.push(animal); + break; + } + } + } + return crew; +} + +console.log("Selected IDs:", selectedArray); + // Here are the candidates and the 'animals' array: let candidateA = { - 'name':'Gordon Shumway', - 'species':'alf', - 'mass':90, - 'o2Used':function(hrs){return 0.035*hrs}, - 'astronautID':414 + name: "Gordon Shumway", + species: "alf", + mass: 90, + o2Used: function (hrs) { + return 0.035 * hrs; + }, + astronautID: 414, }; let candidateB = { - 'name':'Lassie', - 'species':'dog', - 'mass':19.1, - 'o2Used':function(hrs){return 0.030*hrs}, - 'astronautID':503 + name: "Lassie", + species: "dog", + mass: 19.1, + o2Used: function (hrs) { + return 0.03 * hrs; + }, + astronautID: 503, }; let candidateC = { - 'name':'Jonsey', - 'species':'cat', - 'mass':3.6, - 'o2Used':function(hrs){return 0.022*hrs}, - 'astronautID':796 + name: "Jonsey", + species: "cat", + mass: 3.6, + o2Used: function (hrs) { + return 0.022 * hrs; + }, + astronautID: 796, }; let candidateD = { - 'name':'Paddington', - 'species':'bear', - 'mass':31.8, - 'o2Used':function(hrs){return 0.047*hrs}, - 'astronautID':291 + name: "Paddington", + species: "bear", + mass: 31.8, + o2Used: function (hrs) { + return 0.047 * hrs; + }, + astronautID: 291, }; let candidateE = { - 'name':'Pete', - 'species':'tortoise', - 'mass':417, - 'o2Used':function(hrs){return 0.010*hrs}, - 'astronautID':599 + name: "Pete", + species: "tortoise", + mass: 417, + o2Used: function (hrs) { + return 0.01 * hrs; + }, + astronautID: 599, }; let candidateF = { - 'name':'Hugs', - 'species':'ball python', - 'mass':2.3, - 'o2Used':function(hrs){return 0.018*hrs}, - 'astronautID':890 + name: "Hugs", + species: "ball python", + mass: 2.3, + o2Used: function (hrs) { + return 0.018 * hrs; + }, + astronautID: 890, }; -let animals = [candidateA,candidateB,candidateC,candidateD,candidateE,candidateF]; +let animals = [ + candidateA, + candidateB, + candidateC, + candidateD, + candidateE, + candidateF, +]; // Code your template literal and console.log statements: +let crew = buildCrewArray(selectedArray, animals); +console.log(`${crew[0].name}, ${crew[1].name}, and ${crew[2].name} are going to space!`); diff --git a/objects-and-math/studio/ObjectsStudio02.js b/objects-and-math/studio/ObjectsStudio02.js index 987bd46bfe..4a1582efa6 100644 --- a/objects-and-math/studio/ObjectsStudio02.js +++ b/objects-and-math/studio/ObjectsStudio02.js @@ -1,58 +1,97 @@ // Code your orbitCircumference function here: - +function orbitCircumference(radius) { + return Math.round(2 * Math.PI * radius); +} // Code your missionDuration function here: - +function missionDuration(numOrbits, radius = 2000, speed = 28000) { + let circumference = orbitCircumference(radius); + let distance = numOrbits * circumference; + let time = distance / speed; + return parseFloat(time.toFixed(2)); +} // Copy/paste your selectRandomEntry function here: - +function selectRandomEntry(arrayInput) { + return arrayInput[Math.floor(Math.random() * arrayInput.length)]; +} // Code your oxygenExpended function here: - +function oxygenExpended(candidate, radius = 2000, speed = 28000) { + let spacewalkTime = missionDuration(3, radius, speed); + let oxygenUsed = candidate.o2Used(spacewalkTime); + return `${ + candidate.name + } will perform the spacewalk, which will last ${spacewalkTime} hours amd require ${oxygenUsed.toFixed( + 3 + )} kg of oxygen.`; +} // Candidate data & crew array. let candidateA = { - 'name':'Gordon Shumway', - 'species':'alf', - 'mass':90, - 'o2Used':function(hrs){return 0.035*hrs}, - 'astronautID':414 - }; - let candidateB = { - 'name':'Lassie', - 'species':'dog', - 'mass':19.1, - 'o2Used':function(hrs){return 0.030*hrs}, - 'astronautID':503 - }; - let candidateC = { - 'name':'Jonsey', - 'species':'cat', - 'mass':3.6, - 'o2Used':function(hrs){return 0.022*hrs}, - 'astronautID':796 - }; - let candidateD = { - 'name':'Paddington', - 'species':'bear', - 'mass':31.8, - 'o2Used':function(hrs){return 0.047*hrs}, - 'astronautID':291 - }; - let candidateE = { - 'name':'Pete', - 'species':'tortoise', - 'mass':417, - 'o2Used':function(hrs){return 0.010*hrs}, - 'astronautID':599 - }; - let candidateF = { - 'name':'Hugs', - 'species':'ball python', - 'mass':2.3, - 'o2Used':function(hrs){return 0.018*hrs}, - 'astronautID':890 - }; - - let crew = [candidateA,candidateC,candidateE]; - \ No newline at end of file + name: "Gordon Shumway", + species: "alf", + mass: 90, + o2Used: function (hrs) { + return 0.035 * hrs; + }, + astronautID: 414, +}; +let candidateB = { + name: "Lassie", + species: "dog", + mass: 19.1, + o2Used: function (hrs) { + return 0.03 * hrs; + }, + astronautID: 503, +}; +let candidateC = { + name: "Jonsey", + species: "cat", + mass: 3.6, + o2Used: function (hrs) { + return 0.022 * hrs; + }, + astronautID: 796, +}; +let candidateD = { + name: "Paddington", + species: "bear", + mass: 31.8, + o2Used: function (hrs) { + return 0.047 * hrs; + }, + astronautID: 291, +}; +let candidateE = { + name: "Pete", + species: "tortoise", + mass: 417, + o2Used: function (hrs) { + return 0.01 * hrs; + }, + astronautID: 599, +}; +let candidateF = { + name: "Hugs", + species: "ball python", + mass: 2.3, + o2Used: function (hrs) { + return 0.018 * hrs; + }, + astronautID: 890, +}; + +let crew = [candidateA, candidateC, candidateE]; + +let numOrbits = 5; +let orbitRadius = 2000; +let orbitalSpeed = 28000; +let totalDistance = orbitCircumference(orbitRadius) * numOrbits; +let totalDuration = missionDuration(numOrbits, orbitRadius, orbitalSpeed); +console.log( + `The mission will travel ${totalDistance} km around the planet, and it will take ${totalDuration} hours to complete.` +); +let selectedCrewMember = selectRandomEntry(crew); +console.log(oxygenExpended(selectedCrewMember)); diff --git a/objects-and-math/studio/ObjectsStudio03.js b/objects-and-math/studio/ObjectsStudio03.js index 296b74d873..a0e3f5005d 100644 --- a/objects-and-math/studio/ObjectsStudio03.js +++ b/objects-and-math/studio/ObjectsStudio03.js @@ -1,9 +1,34 @@ // Code your crewMass function here: - +function crewMass(crew) { + let totalMass = 0; + for (let member of crew) { + totalMass += member.mass; + } + return parseFloat(totalMass.toFixed(1)); +} // Code your fuelRequired function here: +function fuelRequired(crew, rocketMass = 75000) { + let totalCrewMass = crewMass(crew); + let totalMass = rocketMass + totalCrewMass; + + + let baseFuelRequired = totalMass * 9.5; + + let extraFuel = 0; + for (let member of crew) { + if (member.species === 'dog' || member.species === 'cat') { + extraFuel += 200; + } else { + extraFuel += 100; + } + } + let totalFuelRequired = Math.ceil(baseFuelRequired + extraFuel); + + return totalFuelRequired; +} // The pre-selected crew is in the array at the end of this file. // Feel free to add, remove, or switch crew members as you see fit. @@ -50,5 +75,9 @@ let candidateA = { 'astronautID':890 }; - let crew = [candidateB,candidateD,candidateF]; +let crew = [candidateB, candidateD, candidateF]; + +let totalCrewMass = crewMass(crew); +let totalFuelRequired = fuelRequired(crew); +console.log(`The mission has a launch mass of ${75000 + totalCrewMass} kg and requires ${totalFuelRequired} kg of fuel.`); \ No newline at end of file