Skip to content

Commit 017942b

Browse files
committed
finished exercises
1 parent 356992b commit 017942b

File tree

5 files changed

+45
-9
lines changed

5 files changed

+45
-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: 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+
module.exports = printAll
39+

modules/exercises/index.js

Lines changed: 8 additions & 8 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.js'); //Import functions from averages.js.
4+
const printAll = require('./display.js');//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'];
@@ -18,19 +18,19 @@ for (let i = 0; i<prompts.length; i++){
1818
let response = input.question(`Would you like to ${prompts[i]}? Y/N: `);
1919
if (response.toLowerCase()==='y'){
2020
if (i===0){
21-
//Call 'printAll' here and pass in all necessary arguments.
21+
printAll(astronauts, testTitles, scores)//Call 'printAll' here and pass in all necessary arguments.
2222
} else if (i===1){
2323
for (let j = 0; j<testTitles.length; j++){
24-
let avg = //Call 'averageForTest' here. Pass in j and scores as arguments.
24+
let avg = averages.averageForTest(j, scores) //Call 'averageForTest' here. Pass in j and scores as arguments.
2525
console.log(`${testTitles[j]} test average = ${avg}%.`);
2626
}
2727
} else if (i===2){
2828
for (let j = 0; j<astronauts.length; j++){
29-
let avg = //Call 'averageForStudent' here. Pass in j and scores as arguments.
29+
let avg = averages.averageForStudent(j, scores)//Call 'averageForStudent' here. Pass in j and scores as arguments.
3030
console.log(`${astronauts[j]}'s test average = ${avg}%.`);
3131
}
3232
} else {
33-
let walker = //Call 'randomSelect' to pick a spacewalker from the astronauts array.
33+
let walker = randomSelect(astronauts)//Call 'randomSelect' to pick a spacewalker from the astronauts array.
3434
console.log(`${walker} is the next spacewalker.`);
3535
}
3636
} 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: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
function randomFromArray(arr){
2+
3+
let index = Math.floor(Math.random()*arr.length);
4+
return arr[index];
5+
}
26
//Your code here to select a random element from the array passed to the function.
3-
}
7+
48

59
//TODO: Export the randomFromArray function.
10+
module.exports = randomFromArray

0 commit comments

Comments
 (0)