forked from LaunchCodeEducation/javascript-projects
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added starter code for modules exercises
- Loading branch information
1 parent
824faec
commit fbcd92a
Showing
3 changed files
with
80 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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."); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |