From 12fc22bad100b2efd5bca563374f9676eb88bd57 Mon Sep 17 00:00:00 2001 From: gorjnamron Date: Mon, 14 Sep 2020 18:57:27 -0500 Subject: [PATCH] this is almost complete --- index.html | 2 +- index.js | 93 +++++++++++++++++++++++++++++++++++++++--------------- 2 files changed, 68 insertions(+), 27 deletions(-) diff --git a/index.html b/index.html index 47a9f90c4..d49e1b2a0 100644 --- a/index.html +++ b/index.html @@ -6,6 +6,6 @@ Document - + \ No newline at end of file diff --git a/index.js b/index.js index c2cac5161..86105bcfd 100644 --- a/index.js +++ b/index.js @@ -17,6 +17,8 @@ function processFirstItem(stringList, callback) { return callback(stringList[0]) } +//console.log;(processFirstItem); + // ⭐️ Example Challenge END ⭐️ @@ -27,60 +29,99 @@ function processFirstItem(stringList, callback) { * Study the code for counter1 and counter2. Answer the questions below. * * 1. What is the difference between counter1 and counter2? + * Counter one the variable is inside the function and closure happens at the return function. Counter2 the function has to look outside itself for a globalvarible. * * 2. Which of the two uses a closure? How can you tell? + * Function one uses closure because it closes at the return function. * * 3. In what scenario would the counter1 code be preferable? In what scenario would counter2 be better? + * Counter one would be ideal if there were multiple varibles but only one is intended to print on the console. Counter two would be ideal if it were used to count random objects. * */ // counter1 code -function counterMaker() { - let count = 0; - return function counter() { - count++; - } -} +//function counterMaker() { + //let count = 0; + //return function counter1() { + //count++; + //} +//////} + +///const counter1 = counterMaker(); +//console.log(counter1); + + -const counter1 = counterMaker(); // counter2 code -let count = 0; +//let count = 2; + +//function counter2() { + ///return count++; +//} +//console.log(count()); + -function counter2() { - return count++; -} /* Task 2: inning() -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. */ +Write a function 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(){ + //let number = Math.floor(Math.random() * 3); + //return number +//} + + + //Math.floor(Math.random() * 8); + //function inning() { + + //let count = inning() + //return Math.floor(Math.random() * 3); + + +//console.log(count); +function inning(){ + const gameOne = 'Home' + const gameTwo = 'Away' + let finalInning = Math.floor(Math.random() * 2); + let lastInning = Math.floor(Math.random() * 2); + console.log(`${gameOne} game scored ${finalInning}`); + console.log(`${gameTwo} game scored ${lastInning}`); +} +console.log(inning()); -function inning(/*Code Here*/){ - /*Code Here*/ -} +//*Task 3: finalScore() -/* 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. -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. +//For example, -For example, +//finalScore(inning, 9) might return: +//{ + //const Home + //"Away": 5, +//} -finalScore(inning, 9) might return: -{ - "Home": 11, - "Away": 5, +function finalScore(inning){ + const highScore = "Winning Teams" + console.log(`${highScore} High Score Of ${inning}`); + return inning = Math.floor(Math.random() * 9); + } -*/ +console.log(finalScore(9)); + + + + + -function finalScore(/*code Here*/){ - /*Code Here*/ -} /* Task 4: