Skip to content

Commit fbcd92a

Browse files
committed
added starter code for modules exercises
1 parent 824faec commit fbcd92a

File tree

3 files changed

+80
-0
lines changed

3 files changed

+80
-0
lines changed

modules/exercises/display.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
//TODO: Export ONLY the printAll function.
2+
3+
function printAll(names, tests, scores){
4+
let header = 'Name';
5+
let row = '';
6+
7+
for (let i = 0; i<tests.length; i++){
8+
header += '\t'+tests[i];
9+
}
10+
console.log(header);
11+
12+
for (let name = 0; name<names.length; name++){
13+
row = names[name];
14+
for (let score = 0; score<scores[name].length;score++){
15+
row += '\t'+scores[name][score];
16+
}
17+
console.log(row);
18+
}
19+
return;
20+
}
21+
22+
function printStudentScores(index,students,tests,scores){
23+
console.log(`Test results for ${students[index]}:`);
24+
for (let i = 0; i<tests.length; i++){
25+
console.log(`${tests[i]} = ${scores[index][i]}%.`);
26+
}
27+
return;
28+
}
29+
30+
function printTestScores(index,test,students,scores){
31+
console.log(`Class results for ${test} test:`);
32+
for (let i = 0; i<students.length; i++){
33+
console.log(`${students[i]} = ${scores[i][index]}%.`);
34+
}
35+
return;
36+
}

modules/exercises/index.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
//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.
6+
7+
//Candidate data:
8+
let astronauts = ['Fox','Turtle','Cat','Hippo','Dog'];
9+
10+
const testTitles = ['Math','Fitness','Coding','Nav','Communication'];
11+
12+
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]];
13+
14+
//User interface:
15+
let prompts = ['display all scores', 'average the scores for each test', 'average the scores for each astronaut','select the next spacewalker'];
16+
17+
for (let i = 0; i<prompts.length; i++){
18+
let response = input.question(`Would you like to ${prompts[i]}? Y/N: `);
19+
if (response.toLowerCase()==='y'){
20+
if (i===0){
21+
//Call 'printAll' here and pass in all necessary arguments.
22+
} else if (i===1){
23+
for (let j = 0; j<testTitles.length; j++){
24+
let avg = //Call 'averageForTest' here. Pass in j and scores as arguments.
25+
console.log(`${testTitles[j]} test average = ${avg}%.`);
26+
}
27+
} else if (i===2){
28+
for (let j = 0; j<astronauts.length; j++){
29+
let avg = //Call 'averageForStudent' here. Pass in j and scores as arguments.
30+
console.log(`${astronauts[j]}'s test average = ${avg}%.`);
31+
}
32+
} else {
33+
let walker = //Call 'randomSelect' to pick a spacewalker from the astronauts array.
34+
console.log(`${walker} is the next spacewalker.`);
35+
}
36+
} else {
37+
console.log("Option skipped.");
38+
}
39+
}

modules/exercises/randomSelect.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
function randomFromArray(arr){
2+
//Your code here to select a random element from the array passed to the function.
3+
}
4+
5+
//TODO: Export the randomFromArray function.

0 commit comments

Comments
 (0)