Skip to content

JavaScript-II assignment - #211

Open
ckirkwood94 wants to merge 3 commits into
bloominstituteoftechnology:masterfrom
ckirkwood94:master
Open

JavaScript-II assignment#211
ckirkwood94 wants to merge 3 commits into
bloominstituteoftechnology:masterfrom
ckirkwood94:master

Conversation

@ckirkwood94

Copy link
Copy Markdown

No description provided.

@gooseandmegander

Copy link
Copy Markdown

Thanks for the PR.

@gooseandmegander gooseandmegander left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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}`);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for +=, + works here because the reducer method is already aggregating the results of the return.

Comment thread assignments/closure.js
console.log(`Hey ${name}`);

function greetingFrom() {
console.log(`This is from ${myName}, in case you were wondering`);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Caleb :)

Comment thread assignments/closure.js
sayName();

// ==== Challenge 2: Create a counter function ====
const counter = () => {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants