Skip to content

Commit 71cd477

Browse files
committed
modules exercise completed
1 parent 5f09386 commit 71cd477

File tree

5 files changed

+40
-9
lines changed

5 files changed

+40
-9
lines changed

modules/exercises/ScoreCalcs/averages.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,7 @@ function averageForTest(testIndex,scores){
1717
}
1818

1919
//TODO: Export all functions within an object.
20+
module.exports = {
21+
averageForStudent: averageForStudent,
22+
averageForTest: averageForTest
23+
}

modules/exercises/display.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,4 @@ function printTestScores(index,test,students,scores){
3434
}
3535
return;
3636
}
37+
module.exports = printAll

modules/exercises/index.js

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
//Import modules:
2-
const input = //Import readline-sync.
3-
const averages = //Import functions from averages.js.
4-
const printAll = //Import function from display.js.
5-
const randomSelect = //Import function from randomSelect.js.
1+
const input = require('readline-sync');
2+
const averages = require('./ScoreCalcs/averages.js');
3+
const printAll = require('./display.js');
4+
const randomSelect = require('./randomSelect.js');
65

76
//Candidate data:
87
let astronauts = ['Fox','Turtle','Cat','Hippo','Dog'];
@@ -18,19 +17,19 @@ for (let i = 0; i<prompts.length; i++){
1817
let response = input.question(`Would you like to ${prompts[i]}? Y/N: `);
1918
if (response.toLowerCase()==='y'){
2019
if (i===0){
21-
//Call 'printAll' here and pass in all necessary arguments.
20+
printAll(astronauts, testTitles, scores)
2221
} else if (i===1){
2322
for (let j = 0; j<testTitles.length; j++){
24-
let avg = //Call 'averageForTest' here. Pass in j and scores as arguments.
23+
let avg = averages.averageForTest(j, scores)
2524
console.log(`${testTitles[j]} test average = ${avg}%.`);
2625
}
2726
} else if (i===2){
2827
for (let j = 0; j<astronauts.length; j++){
29-
let avg = //Call 'averageForStudent' here. Pass in j and scores as arguments.
28+
let avg = averages.averageForStudent(j, scores)
3029
console.log(`${astronauts[j]}'s test average = ${avg}%.`);
3130
}
3231
} else {
33-
let walker = //Call 'randomSelect' to pick a spacewalker from the astronauts array.
32+
let walker = randomSelect(astronauts)
3433
console.log(`${walker} is the next spacewalker.`);
3534
}
3635
} else {

modules/exercises/package-lock.json

Lines changed: 24 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

modules/exercises/randomSelect.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
function randomFromArray(arr){
22
//Your code here to select a random element from the array passed to the function.
3+
let index = Math.floor(Math.random()*arr.length);
4+
return arr[index];
35
}
46

57
//TODO: Export the randomFromArray function.
8+
module.exports = randomFromArray

0 commit comments

Comments
 (0)