Skip to content

Commit ea61c9e

Browse files
Quinton KornegayQuinton Kornegay
authored andcommitted
Modules Exercise
1 parent 15ccb99 commit ea61c9e

File tree

4 files changed

+18
-7
lines changed

4 files changed

+18
-7
lines changed

modules/exercises/ScoreCalcs/averages.js

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

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

modules/exercises/display.js

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

modules/exercises/index.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
//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.
2+
const input = require('readline-sync')//Import readline-sync.
3+
const averages = require("./ScoreCalcs/averages"); //Import functions from averages.js.
4+
const printAll = require("./display"); //Import function from display.js.
5+
const randomSelect = require("./randomSelect"); //Import function from randomSelect.js.
66

77
//Candidate data:
88
let astronauts = ['Fox','Turtle','Cat','Hippo','Dog'];
@@ -19,18 +19,19 @@ for (let i = 0; i<prompts.length; i++){
1919
if (response.toLowerCase()==='y'){
2020
if (i===0){
2121
//Call 'printAll' here and pass in all necessary arguments.
22+
printAll(astronauts, testTitles, scores);
2223
} else if (i===1){
2324
for (let j = 0; j<testTitles.length; j++){
24-
let avg = //Call 'averageForTest' here. Pass in j and scores as arguments.
25+
let avg = averages.averageForTest(j, scores); //Call 'averageForTest' here. Pass in j and scores as arguments.
2526
console.log(`${testTitles[j]} test average = ${avg}%.`);
2627
}
2728
} else if (i===2){
2829
for (let j = 0; j<astronauts.length; j++){
29-
let avg = //Call 'averageForStudent' here. Pass in j and scores as arguments.
30+
let avg = averages.averageForStudent(j, scores);//Call 'averageForStudent' here. Pass in j and scores as arguments.
3031
console.log(`${astronauts[j]}'s test average = ${avg}%.`);
3132
}
3233
} else {
33-
let walker = //Call 'randomSelect' to pick a spacewalker from the astronauts array.
34+
let walker = randomSelect(astronauts); //Call 'randomSelect' to pick a spacewalker from the astronauts array.
3435
console.log(`${walker} is the next spacewalker.`);
3536
}
3637
} else {

modules/exercises/randomSelect.js

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

56
//TODO: Export the randomFromArray function.
7+
module.exports = randomFromArray

0 commit comments

Comments
 (0)