JavaScript-II assignment - #211
Conversation
|
Thanks for the PR. |
gooseandmegander
left a comment
There was a problem hiding this comment.
Everything looks great, Caleb. I have some comments for you to review. Go for stretch!
| // The event director needs both the first and last names of each runner for their running bibs. Combine both the first and last names into a new array called fullName. | ||
| let fullName = []; | ||
| runners.forEach(function(element) { | ||
| fullName.push(`${element.first_name} ${element.last_name}`); |
There was a problem hiding this comment.
Nice use of template literals!
| // The donations need to be tallied up and reported for tax purposes. Add up all the donations into a ticketPriceTotal array and log the result | ||
| let ticketPriceTotal = []; | ||
| let ticketPriceTotal = runners.reduce((theReducer, element) =>{ | ||
| return theReducer += element.donation; |
There was a problem hiding this comment.
No need for +=, + works here because the reducer method is already aggregating the results of the return.
| console.log(`Hey ${name}`); | ||
|
|
||
| function greetingFrom() { | ||
| console.log(`This is from ${myName}, in case you were wondering`); |
| sayName(); | ||
|
|
||
| // ==== Challenge 2: Create a counter function ==== | ||
| const counter = () => { |
There was a problem hiding this comment.
This is how I tweaked yours to have closure:
const counter = () => {
// Return a function that when invoked increments and returns a counter variable.
let value = null;
return function newCounter() {
console.log((value += 1));
};
};
const Acounter = counter();
console.log(Acounter());
console.log(Acounter());
The closure is created in Acounter, not counter(). Counter creates and destroys its scope whenever it is called. The Acounter needs to be set equal to the returned counter function outside of the counter function scope.
No description provided.