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
randomFromArray
function. 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-sync
to theinput
variable.const input = require('readline-sync');
Assign the
printAll
function fromdisplay.js
to theprintAll
variable.const printAll = require('./display.js');
Finish the Project¶
Line 21 - Call
printAll
to 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);