In the exercises, you created objects to store data about the candidates for our animal astronaut corps. For this studio, we provide you with a ready-made set of candidates.
You must create code to:
To access the code for exercise 1, open this repl.it link.
Each candidate was assigned an ID number, which is stored in the candidate's
data file and in the
selectRandomEntryfunction to select a random entry from the
idNumbersarray. Review the Combining Math Methods section if you need a reminder on how to do this.
arrayName.includes(item) can be used to check if the array already contains
while loop can keep the selection process going until the
desired number of entries have been added to the array.
Design a function that takes two arrays as parameters. These hold the randomly selected ID numbers and the candidate objects.
Use one or more loops to check which animals hold the lucky ID numbers. They
will be going on the space mission! Store these animals in a
and then return that array.
Use a template literal to print,
'____, ____, and ____ are going to space!'
Fill in the blanks with the names of the selected animals.
To access the code for the orbit calculations and first bonus mission, go to repl.it.
Spacecraft orbits are not circular, but we will assume that our mission is special. The animals will achieve a circular orbit with an altitude of 2000 km.
Define a function that returns the circumference (C = 2πr) of the orbit. Round the circumference to an integer.
missionDuration function to take three parameters - the
number of orbits completed, the orbit radius, and the orbital speed. Set
the default radius to 2000 km and the default orbital speed to
Calculate how long it will take our animals to complete a certain number
of orbits (
time = distance/speed). Round the answer to 2 decimal
places, then return the result.
For example, with the default radius and speed, 5 orbits will take about
'The mission will travel ____ km around the planet, and it will
take ____ hours to complete.'
Time for an excursion! Code an
oxygenExpended function to accomplish the
The function should take a candidate object as a parameter and NOT the
When you call
oxygenExpended, feel free to use your
selectRandomEntry to pick the crew member to pass into the
The spacewalk will last for three orbits around the earth. Use
missionDuration to calculate how many hours the spacewalk will take.
Use the candidate's
o2Used method to calculate how much oxygen (O 2)
they consume during the spacewalk. Round the answer to 3 decimal places.
Return the string,
'__ will perform the spacewalk, which will last __
hours and require __ kg of oxygen.' Fill in the blanks with the
animal's name, the spacewalk time, and the amount of O 2 used.
We should not restrict our mission to the default values for orbital
radius and orbital speed. Refactor
oxygenExpended to accept values
for these items. Remember to include the values in the
Instead of randomly selecting a crew member for the spacewalk, have your program select the animal with the smallest oxygen consumption.
To access the code for this bonus mission, go to repl.it.
A general rule of thumb states that it takes about 9 - 10 kg of rocket fuel to lift 1 kg of mass into low-earth orbit (LEO). For our mission, we will assume a value of 9.5 kg to calculate how much fuel we need to launch our crew into space.
crewMassfunction that returns the total mass of the selected crew members rounded to 1 decimal place.
fuelRequiredfunction to combine the rocket and crew masses, then calculate and return the amount of fuel needed to reach LEO.
fuelRequiredto account for this, then round the final amount of fuel UP to the nearest integer.
'The mission has a launch mass of ____ kg and requires ____ kg of fuel.'Fill in the blanks with the calculated amounts.