Exercise Solutions: Modules¶
Export Finished Modules¶
In
averages.js, add code to export all of the functions within an object.1 2 3 4
module.exports = { averageForStudent: averageForStudent, averageForTest: averageForTest };
Code and Export a New Module¶
Add code to complete the
randomFromArrayfunction. It should take an array as an argument and then return a randomly selected element from that array.1 2 3 4
function randomFromArray(arr){ let index = Math.floor(Math.random()*arr.length); return arr[index]; }
Import Required Modules¶
Assign
readline-syncto theinputvariable.const input = require('readline-sync');
Assign the
printAllfunction fromdisplay.jsto theprintAllvariable.const printAll = require('./display.js');
Finish the Project¶
Line 21 - Call
printAllto display all of the tests and student scores. Be sure to pass in the correct arguments.21
printAll(astronauts, testTitles, scores);
Line 29 - Call
averageForStudent(with the proper arguments) to print each astronaut's average score.29
let avg = averages.averageForStudent(j, scores);
