1- // Code your orbitCircumference function here:
1+ // Candidate data & crew array.
2+ let candidateA = {
3+ name : "Gordon Shumway" ,
4+ species : "alf" ,
5+ mass : 90 ,
6+ o2Used : function ( hrs ) {
7+ return 0.035 * hrs ;
8+ } ,
9+ astronautID : 414 ,
10+ } ;
11+ let candidateB = {
12+ name : "Lassie" ,
13+ species : "dog" ,
14+ mass : 19.1 ,
15+ o2Used : function ( hrs ) {
16+ return 0.03 * hrs ;
17+ } ,
18+ astronautID : 503 ,
19+ } ;
20+ let candidateC = {
21+ name : "Jonsey" ,
22+ species : "cat" ,
23+ mass : 3.6 ,
24+ o2Used : function ( hrs ) {
25+ return 0.022 * hrs ;
26+ } ,
27+ astronautID : 796 ,
28+ } ;
29+ let candidateD = {
30+ name : "Paddington" ,
31+ species : "bear" ,
32+ mass : 31.8 ,
33+ o2Used : function ( hrs ) {
34+ return 0.047 * hrs ;
35+ } ,
36+ astronautID : 291 ,
37+ } ;
38+ let candidateE = {
39+ name : "Pete" ,
40+ species : "tortoise" ,
41+ mass : 417 ,
42+ o2Used : function ( hrs ) {
43+ return 0.01 * hrs ;
44+ } ,
45+ astronautID : 599 ,
46+ } ;
47+ let candidateF = {
48+ name : "Hugs" ,
49+ species : "ball python" ,
50+ mass : 2.3 ,
51+ o2Used : function ( hrs ) {
52+ return 0.018 * hrs ;
53+ } ,
54+ astronautID : 890 ,
55+ } ;
256
57+ let crew = [ candidateA , candidateC , candidateE ] ;
58+ const numOrbits = 5 ;
59+
60+ // Code your orbitCircumference function here:
61+ const calculateOrbitCircumference = ( radius ) => {
62+ const circumference = 2 * Math . PI * radius ;
63+ return Math . round ( circumference ) ;
64+ } ;
365
466// Code your missionDuration function here:
67+ const missionDuration = (
68+ numOrbits ,
69+ orbitRadius = 2000 ,
70+ orbitalSpeed = 28000
71+ ) => {
72+ const orbitCircumference = calculateOrbitCircumference ( orbitRadius ) ;
73+ const distance = numOrbits * orbitCircumference ;
74+ const timeInHours = distance / orbitalSpeed ;
75+ const roundedTime = timeInHours . toFixed ( 2 ) ;
76+ return parseFloat ( roundedTime ) ;
77+ } ;
578
79+ function selectRandomEntry ( array ) {
80+ const randomIndex = Math . floor ( Math . random ( ) * array . length ) ;
81+ return array [ randomIndex ] ;
82+ }
683
7- // Copy/paste your selectRandomEntry function here:
84+ const oxygenExpended = ( candidate , numOrbits , orbitRadius , orbitalSpeed ) => {
85+ const spacewalkTime = missionDuration ( numOrbits , orbitRadius , orbitalSpeed ) ;
86+ const oxygenUsed = candidate . o2Used ( spacewalkTime ) ;
87+ return `${
88+ candidate . name
89+ } will perform the spacewalk, which will last ${ spacewalkTime . toFixed (
90+ 2
91+ ) } hours and require ${ oxygenUsed . toFixed ( 3 ) } kg of oxygen.`;
92+ } ;
893
94+ let orbitRadius = 2000 ;
95+ let orbitalSpeed = 28000 ;
96+ const selectedCandidate = selectRandomEntry ( crew ) ;
97+ const spacewalkInfo = oxygenExpended (
98+ selectedCandidate ,
99+ numOrbits ,
100+ orbitRadius ,
101+ orbitalSpeed
102+ ) ;
9103
10- // Code your oxygenExpended function here:
104+ console . log (
105+ `The circumference of the orbit is approximately ${ calculateOrbitCircumference (
106+ orbitRadius
107+ ) } kilometers.`
108+ ) ;
11109
110+ const duration = missionDuration ( numOrbits , orbitRadius , orbitalSpeed ) ;
111+ console . log (
112+ `The mission will travel ${
113+ calculateOrbitCircumference ( orbitRadius ) * numOrbits
114+ } km around the planet, and it will take ${ duration } hours to complete.`
115+ ) ;
12116
13- // Candidate data & crew array.
14- let candidateA = {
15- 'name' :'Gordon Shumway' ,
16- 'species' :'alf' ,
17- 'mass' :90 ,
18- 'o2Used' :function ( hrs ) { return 0.035 * hrs } ,
19- 'astronautID' :414
20- } ;
21- let candidateB = {
22- 'name' :'Lassie' ,
23- 'species' :'dog' ,
24- 'mass' :19.1 ,
25- 'o2Used' :function ( hrs ) { return 0.030 * hrs } ,
26- 'astronautID' :503
27- } ;
28- let candidateC = {
29- 'name' :'Jonsey' ,
30- 'species' :'cat' ,
31- 'mass' :3.6 ,
32- 'o2Used' :function ( hrs ) { return 0.022 * hrs } ,
33- 'astronautID' :796
34- } ;
35- let candidateD = {
36- 'name' :'Paddington' ,
37- 'species' :'bear' ,
38- 'mass' :31.8 ,
39- 'o2Used' :function ( hrs ) { return 0.047 * hrs } ,
40- 'astronautID' :291
41- } ;
42- let candidateE = {
43- 'name' :'Pete' ,
44- 'species' :'tortoise' ,
45- 'mass' :417 ,
46- 'o2Used' :function ( hrs ) { return 0.010 * hrs } ,
47- 'astronautID' :599
48- } ;
49- let candidateF = {
50- 'name' :'Hugs' ,
51- 'species' :'ball python' ,
52- 'mass' :2.3 ,
53- 'o2Used' :function ( hrs ) { return 0.018 * hrs } ,
54- 'astronautID' :890
55- } ;
56-
57- let crew = [ candidateA , candidateC , candidateE ] ;
58-
117+ console . log ( spacewalkInfo ) ;
0 commit comments