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
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
<title>Document</title>
</head>
<body>
<script scr="index.js"></script>
<script src="index.js"></script>
</body>
</html>
93 changes: 67 additions & 26 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
function processFirstItem(stringList, callback) {
return callback(stringList[0])
}
//console.log;(processFirstItem);


// ⭐️ Example Challenge END ⭐️

Expand All @@ -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:

Expand Down