|
1 | 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. |
| 2 | +const input = require('readline-sync'); //Import readline-sync. |
| 3 | +const averages = require('../exercises/ScoreCalcs/averages.js'); //Import functions from averages.js. |
| 4 | +const printAll = require('./display.js'); //Import function from display.js. |
| 5 | +const randomSelect = require('./randomSelect.js'); //Import function from randomSelect.js. |
6 | 6 |
|
7 | 7 | //Candidate data:
|
8 |
| -let astronauts = ['Fox','Turtle','Cat','Hippo','Dog']; |
| 8 | +let astronauts = ['Fox', 'Turtle', 'Cat', 'Hippo', 'Dog']; |
9 | 9 |
|
10 |
| -const testTitles = ['Math','Fitness','Coding','Nav','Communication']; |
| 10 | +const testTitles = ['Math', 'Fitness', 'Coding', 'Nav', 'Communication']; |
11 | 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]]; |
| 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 | 13 |
|
14 | 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']; |
| 15 | +let prompts = ['display all scores', 'average the scores for each test', 'average the scores for each astronaut', 'select the next spacewalker']; |
16 | 16 |
|
17 |
| -for (let i = 0; i<prompts.length; i++){ |
| 17 | +for (let i = 0; i < prompts.length; i++) { |
18 | 18 | let response = input.question(`Would you like to ${prompts[i]}? Y/N: `);
|
19 |
| - if (response.toLowerCase()==='y'){ |
20 |
| - if (i===0){ |
| 19 | + if (response.toLowerCase() === 'y') { |
| 20 | + if (i === 0) { |
21 | 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. |
| 22 | + printAll.printAll(astronauts, testTitles, scores); |
| 23 | + } else if (i === 1) { |
| 24 | + for (let j = 0; j < testTitles.length; j++) { |
| 25 | + let avg = averages.averageForTest(j, scores); //Call 'averageForTest' here. Pass in j and scores as arguments. |
25 | 26 | console.log(`${testTitles[j]} test average = ${avg}%.`);
|
26 | 27 | }
|
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. |
| 28 | + } else if (i === 2) { |
| 29 | + for (let j = 0; j < astronauts.length; j++) { |
| 30 | + let avg = averages.averageForStudent(j, scores); //Call 'averageForStudent' here. Pass in j and scores as arguments. |
30 | 31 | console.log(`${astronauts[j]}'s test average = ${avg}%.`);
|
31 | 32 | }
|
32 | 33 | } else {
|
33 |
| - let walker = //Call 'randomSelect' to pick a spacewalker from the astronauts array. |
| 34 | + let walker = randomSelect.randomFromArray(astronauts); //Call 'randomSelect' to pick a spacewalker from the astronauts array. |
34 | 35 | console.log(`${walker} is the next spacewalker.`);
|
35 | 36 | }
|
36 | 37 | } else {
|
|
0 commit comments