Skip to content

Commit

Permalink
added starter code for modules exercises
Browse files Browse the repository at this point in the history
  • Loading branch information
jwoolbright23 committed Sep 12, 2023
1 parent 824faec commit fbcd92a
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 0 deletions.
36 changes: 36 additions & 0 deletions modules/exercises/display.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//TODO: Export ONLY the printAll function.

function printAll(names, tests, scores){
let header = 'Name';
let row = '';

for (let i = 0; i<tests.length; i++){
header += '\t'+tests[i];
}
console.log(header);

for (let name = 0; name<names.length; name++){
row = names[name];
for (let score = 0; score<scores[name].length;score++){
row += '\t'+scores[name][score];
}
console.log(row);
}
return;
}

function printStudentScores(index,students,tests,scores){
console.log(`Test results for ${students[index]}:`);
for (let i = 0; i<tests.length; i++){
console.log(`${tests[i]} = ${scores[index][i]}%.`);
}
return;
}

function printTestScores(index,test,students,scores){
console.log(`Class results for ${test} test:`);
for (let i = 0; i<students.length; i++){
console.log(`${students[i]} = ${scores[i][index]}%.`);
}
return;
}
39 changes: 39 additions & 0 deletions modules/exercises/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
//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.

//Candidate data:
let astronauts = ['Fox','Turtle','Cat','Hippo','Dog'];

const testTitles = ['Math','Fitness','Coding','Nav','Communication'];

let scores = [[95, 86, 83, 81, 76],[79, 71, 79, 87, 72],[94, 87, 87, 83, 82],[99, 77, 91, 79, 80],[96, 95, 99, 82, 70]];

//User interface:
let prompts = ['display all scores', 'average the scores for each test', 'average the scores for each astronaut','select the next spacewalker'];

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){
for (let j = 0; j<testTitles.length; j++){
let avg = //Call 'averageForTest' here. Pass in j and scores as arguments.
console.log(`${testTitles[j]} test average = ${avg}%.`);
}
} else if (i===2){
for (let j = 0; j<astronauts.length; j++){
let avg = //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.
console.log(`${walker} is the next spacewalker.`);
}
} else {
console.log("Option skipped.");
}
}
5 changes: 5 additions & 0 deletions modules/exercises/randomSelect.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
function randomFromArray(arr){
//Your code here to select a random element from the array passed to the function.
}

//TODO: Export the randomFromArray function.

0 comments on commit fbcd92a

Please sign in to comment.