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 idNumbers
array.
selectRandomEntry
function to select a random entry from the
idNumbers
array. Review the
Combining Math Methods section if you need a
reminder on how to do this.Tip
arrayName.includes(item)
can be used to check if the array already contains
item
. A while
loop can keep the selection process going until the
desired number of entries have been added to the array.
crew
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 crew
array,
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.
Define the 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
28000 km/hr.
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
2.24 hours
.
Print, '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
following:
The function should take a candidate object as a parameter and NOT the
crew
array.
Note
When you call oxygenExpended
, feel free to use your
selectRandomEntry
to pick the crew member to pass into the
function.
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
missionDuration
call.
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.
crewMass
function that returns the total mass of the selected
crew members rounded to 1 decimal place.fuelRequired
function to combine the rocket and crew
masses, then calculate and return the amount of fuel needed to reach LEO.fuelRequired
to 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.