Skip to content

Commit

Permalink
Modules exercises completed
Browse files Browse the repository at this point in the history
  • Loading branch information
craigb28 committed Feb 5, 2024
1 parent 72afb47 commit 49f5111
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 11 deletions.
5 changes: 5 additions & 0 deletions modules/exercises/ScoreCalcs/averages.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,8 @@ function averageForTest(testIndex,scores){
}

//TODO: Export all functions within an object.

module.exports = {
averageForStudent:averageForStudent,
averageForTest:averageForTest
};
2 changes: 2 additions & 0 deletions modules/exercises/display.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,5 @@ function printTestScores(index,test,students,scores){
}
return;
}

module.exports = printAll;
26 changes: 15 additions & 11 deletions modules/exercises/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
//Import modules:
const input = //Import readline-sync.
const averages = //Import functions from averages.js.
const printAll = //Import function from display.js.
const randomSelect = //Import function from randomSelect.js.
const input = require('readline-sync'); //Import readline-sync.
const averages = require('./ScoreCalcs/averages.js'); //Import functions from averages.js.
const printAll = require('./display.js') //Import function from display.js.
const randomSelect = require('./randomSelect.js') //Import function from randomSelect.js.

//Candidate data:
let astronauts = ['Fox','Turtle','Cat','Hippo','Dog'];
Expand All @@ -16,21 +16,25 @@ let prompts = ['display all scores', 'average the scores for each test', 'averag

for (let i = 0; i<prompts.length; i++){
let response = input.question(`Would you like to ${prompts[i]}? Y/N: `);

if (response.toLowerCase()==='y'){
if (i===0){
//Call 'printAll' here and pass in all necessary arguments.
} else if (i===1){
printAll(astronauts, testTitles, scores);//Call 'printAll' here and pass in all necessary arguments.
}
else if (i===1){
for (let j = 0; j<testTitles.length; j++){
let avg = //Call 'averageForTest' here. Pass in j and scores as arguments.
let avg = averages.averageForTest(j,scores);//Call 'averageForTest' here. Pass in j and scores as arguments.
console.log(`${testTitles[j]} test average = ${avg}%.`);
}
} else if (i===2){
}
else if (i===2){
for (let j = 0; j<astronauts.length; j++){
let avg = //Call 'averageForStudent' here. Pass in j and scores as arguments.
let avg = averages.averageForStudent(j, scores);//Call 'averageForStudent' here. Pass in j and scores as arguments.
console.log(`${astronauts[j]}'s test average = ${avg}%.`);
}
} else {
let walker = //Call 'randomSelect' to pick a spacewalker from the astronauts array.
}
else {
let walker = randomSelect(astronauts);//Call 'randomSelect' to pick a spacewalker from the astronauts array.
console.log(`${walker} is the next spacewalker.`);
}
} else {
Expand Down
24 changes: 24 additions & 0 deletions modules/exercises/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions modules/exercises/randomSelect.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
function randomFromArray(arr){
let i = Math.floor(Math.random()*arr.length);
return arr[i];
//Your code here to select a random element from the array passed to the function.
}

//TODO: Export the randomFromArray function.
module.exports = randomFromArray;

0 comments on commit 49f5111

Please sign in to comment.