From 74a426983ae32ea3f5e1286395fdc4feb24c8ab6 Mon Sep 17 00:00:00 2001 From: rudy35hernandez Date: Wed, 30 Sep 2020 17:30:54 -0700 Subject: [PATCH 1/3] task 1 out the way --- index.html | 1 + index.js | 35 ++++++++++++++++++++++++++++++----- 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/index.html b/index.html index fdb306537..a45b9ffcb 100644 --- a/index.html +++ b/index.html @@ -3,6 +3,7 @@ + Document diff --git a/index.js b/index.js index c2cac5161..1e6200040 100644 --- a/index.js +++ b/index.js @@ -28,10 +28,20 @@ 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? * + * Both have closure. The first has a variable that is local which can run the function. + * The second uses a global variable which creates the closure. So both have closure. + * * 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 @@ -57,10 +67,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() @@ -76,9 +88,22 @@ finalScore(inning, 9) might return: */ -function finalScore(/*code Here*/){ +function finalScore( ){ + + let gameScore = [ + { + home: home, + away: away, + } + + ] + return gameScore; +}; + + console.log(finalScore()); + - /*Code Here*/ + } From 3f8249278b7871d5bfaf9b7ddf0dde81ac35b1bc Mon Sep 17 00:00:00 2001 From: rudy35hernandez Date: Thu, 1 Oct 2020 18:19:12 -0700 Subject: [PATCH 2/3] almmost done --- index.js | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/index.js b/index.js index 1e6200040..6cdee222c 100644 --- a/index.js +++ b/index.js @@ -34,8 +34,7 @@ function processFirstItem(stringList, callback) { * * 2. Which of the two uses a closure? How can you tell? * - * Both have closure. The first has a variable that is local which can run the function. - * The second uses a global variable which creates the closure. So both have closure. + * The * * 3. In what scenario would the counter1 code be preferable? In what scenario would counter2 be better? * @@ -88,25 +87,29 @@ finalScore(inning, 9) might return: */ -function finalScore( ){ +function finalScore(inning, num){ + + let score1 = 0; + let score2 = 0; + + for(let i = 0; i < num; i++){ + score1 = score1 + inning() + score2 = score2 + inning() + } + - let gameScore = [ + let inningCount = { - home: home, - away: away, + home: score1, + away: score2, } - ] - return gameScore; + return inningCount; }; - console.log(finalScore()); - - +console.log(finalScore(inning, 9)) -} - /* Task 4: Create a function called `scoreboard` that accepts the following parameters: From 47bc1afb9cdcf33b4150b6e9a2b5f4d35b1772dd Mon Sep 17 00:00:00 2001 From: rudy35hernandez Date: Thu, 1 Oct 2020 22:55:13 -0700 Subject: [PATCH 3/3] task 4 done but i keep getting {object Object} instead of the score. --- index.js | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index 6cdee222c..f290fd469 100644 --- a/index.js +++ b/index.js @@ -34,7 +34,9 @@ function processFirstItem(stringList, callback) { * * 2. Which of the two uses a closure? How can you tell? * - * The + * 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? * @@ -132,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)); +