Skip to content
Open
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="index.js"></script>
<title>Document</title>
</head>
<body>
Expand Down
55 changes: 46 additions & 9 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,21 @@ function processFirstItem(stringList, callback) {
*
* 1. What is the difference between counter1 and counter2?
*
*
* Counter 1 has a local variable inside its function that can not be accessed outside the function.
* Counter 2 uses a global variable inside its function to
*
* 2. Which of the two uses a closure? How can you tell?
*
* The second uses a closure. It has a variable that it calls upon that is directly inside its function,
* and it also executes the function with return. The first one does not complete a function as there is
* no return command.
*
* 3. In what scenario would the counter1 code be preferable? In what scenario would counter2 be better?
*
*
* Counter1 would be preferable if the count variable is not to be used ever again in the script. We want
* to keep the code as clean as possible. We don't want a variable hanging out with no purpose.
* The counter2 code would be useful if we plan on using the count variable down the line in our code.
*/

// counter1 code
Expand All @@ -57,10 +68,12 @@ 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*/){
const randomScore = Math.floor(Math.random() * 3);
return randomScore;
}

/*Code Here*/
console.log(inning());

}

/* Task 3: finalScore()

Expand All @@ -76,11 +89,28 @@ finalScore(inning, 9) might return:

*/

function finalScore(/*code Here*/){
function finalScore(inning, num){

let score1 = 0;
let score2 = 0;

for(let i = 0; i < num; i++){
score1 = score1 + inning()
score2 = score2 + inning()
}


let inningCount =
{
home: score1,
away: score2,
}

/*Code Here*/
return inningCount;
};

}
console.log(finalScore(inning, 9))


/* Task 4:

Expand All @@ -104,8 +134,15 @@ and returns the score at each pont in the game, like so:

Final Score: awayTeam - homeTeam */

function scoreboard(/* CODE HERE */) {
/* CODE HERE */
}
function scoreboard(getInningScore, whichInning, num) {
let twoScores = [];
for(let i = 0; i < num; i++){
twoScores.push(`Innings ${i+1}: ${getInningScore(whichInning, 1)}`);
}
return twoScores;
}

console.log(scoreboard(finalScore, inning, 9));