Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 29 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,16 @@ function processFirstItem(stringList, callback) {
*
* 1. What is the difference between counter1 and counter2?
*
* Counter 1 is two functions nested inside eachother and counter2 is one function. Counter 1 also has the let count variable function scoped so other functions can't access it.
*
* 2. Which of the two uses a closure? How can you tell?
*
* counter1 uses a closure because of the function nested inside of it.
*
* 3. In what scenario would the counter1 code be preferable? In what scenario would counter2 be better?
*
* Counter1 code is preferable when you don't want any other part of your program to use the code or variables nested inside counter1. Vice versa with counter2
*
*/

// counter1 code
Expand All @@ -56,12 +62,15 @@ function counter2() {

Write a function called `inning` that generates a random number of points that a team scored in an inning. This should be a whole number between 0 and 2. */

function inning(/*Code Here*/){

/*Code Here*/

function inning(inning, min, max){
min = Math.ceil(0);
max = Math.floor(2);
let score = Math.floor(Math.random() * (max - min + 1)) + min;
return `In inning ${inning} team A scored ${score}`
}

console.log(inning(3, 0, 2))

/* Task 3: finalScore()

Write a higher order function called `finalScore` that accepts the callback function `inning` (from above) and a number of innings and and returns the final score of the game in the form of an object.
Expand All @@ -76,12 +85,25 @@ finalScore(inning, 9) might return:

*/

function finalScore(/*code Here*/){

/*Code Here*/
function finalScore(callback, inning){
let home = 0;
let away = 0;
for (let i = 0; i < inning; i++) {
home = callback
}
for (let i = 0; i < inning; i++) {
away = callback
}

const obj = {
"Home": home,
"Away": away
}
return obj
}

console.log(finalScore(inning, 9))

/* Task 4:

Create a function called `scoreboard` that accepts the following parameters:
Expand Down