Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

first commit #226

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
26 changes: 19 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,17 @@ console.log('example task:', processFirstItem(['foo','bar'],function(str){return
Study the code for counter1 and counter2, then answer the questions below.

1. What is the difference between counter1 and counter2?

counter1 defines the variable 'count' inside of the function. (function scoped) counter2 defines the variable 'count' in the global space. (global scoped)

2. Which of the two uses a closure? How can you tell?

counter1 uses a closure because it defines the variable within the function.

3. In what scenario would the counter1 code be preferable? In what scenario would
counter2 be better?

counter1 would be preferred when you want it to reset every time it is used. counter2 is better when you want the count to be stored for later use.
*/

// counter1 code
Expand Down Expand Up @@ -64,8 +70,8 @@ Use the inning function below to do the following:
NOTE: This will be a callback function for the tasks below
*/

function inning(/*Code Here*/){
/*Code Here*/
function inning(){
return Math.floor(Math.random()*3)
}


Expand All @@ -83,9 +89,15 @@ Use the finalScore function below to do the following:
}
*/

function finalScore(/*Code Here*/){
/*Code Here*/
function finalScore(inning, inningsPlayed){
let homeScore = 0;
let awayScore = 0;
for (let i = 0; i< inningsPlayed; i++){
homeScore += inning();
awayScore += inning();
} return{'Home': homeScore,'Away': awayScore}
}
console.log(finalScore(inning, 9))


/* ⚾️⚾️⚾️ Task 4: getInningScore() ⚾️⚾️⚾️
Expand All @@ -101,10 +113,10 @@ For example: invoking getInningScore(inning) might return this object:
*/


function getInningScore(/*Your Code Here */) {
/*Your Code Here */

function getInningScore(inning) {
return {'Home': inning(), "Away": inning()}
}
console.log(getInningScore(inning))


/* STRETCH: ⚾️⚾️⚾️ Task 5: scoreboard() ⚾️⚾️⚾️
Expand Down