Skip to content

Commit 16398d9

Browse files
committed
Modules Exercises
1 parent f1ca96c commit 16398d9

15 files changed

Lines changed: 3789 additions & 9 deletions

File tree

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: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
//TODO: Export ONLY the printAll function.
2+
module.exports = printAll;
3+
24

35
function printAll(names, tests, scores){
46
let header = 'Name';
@@ -34,3 +36,5 @@ function printTestScores(index,test,students,scores){
3436
}
3537
return;
3638
}
39+
40+

modules/exercises/index.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
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.js'); //Import functions from averages.js.
4+
const printAll = require('./display.js'); //Import function from display.js.
5+
const randomSelect = require('./randomSelect.js'); //Import function from randomSelect.js.
6+
const { averageForTest } = require('./ScoreCalcs/averages.js');
67

78
//Candidate data:
89
let astronauts = ['Fox','Turtle','Cat','Hippo','Dog'];
@@ -18,19 +19,19 @@ for (let i = 0; i<prompts.length; i++){
1819
let response = input.question(`Would you like to ${prompts[i]}? Y/N: `);
1920
if (response.toLowerCase()==='y'){
2021
if (i===0){
21-
//Call 'printAll' here and pass in all necessary arguments.
22+
printAll(astronauts, testTitles, scores); //Call 'printAll' here and pass in all necessary arguments.
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/node_modules/.package-lock.json

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

modules/exercises/node_modules/readline-sync/LICENSE

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

modules/exercises/node_modules/readline-sync/README-Deprecated.md

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

0 commit comments

Comments
 (0)