Kevin Nguyen's Javascript II pull - #230
Conversation
| // ==== Challenge 1: Use .forEach() ==== | ||
| // 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(runner => fullName.push({"first_name":runner.first_name, "last_name":runner.last_name})); |
There was a problem hiding this comment.
This is good! Though you only needed to push the first and last names into the array, I like to see that you're familiar with adding strings as well.
| // ==== Challenge 2: Use .map() ==== | ||
| // The event director needs to have all the runner's first names converted to uppercase because the director BECAME DRUNK WITH POWER. Convert each first name into all caps and log the result | ||
| let allCaps = []; | ||
| let allCaps = runners.map(runner => runner.first_name.toUpperCase()); |
| // ==== Challenge 3: Use .filter() ==== | ||
| // The large shirts won't be available for the event due to an ordering issue. Get a list of runners with large sized shirts so they can choose a different size. Return an array named largeShirts that contains information about the runners that have a shirt size of L and log the result | ||
| let largeShirts = []; | ||
| let largeShirts = runners.filter(runner => runner.shirt_size=="L"); |
There was a problem hiding this comment.
Good! Remember to use ===, (look up the difference between == and ===), and space around the operator.
| // ==== Challenge 4: Use .reduce() ==== | ||
| // 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 = []; | ||
| ticketPriceTotal.push(runners.reduce((ticketSales, runner) => {return ticketSales+=runner.donation}, 0)); |
There was a problem hiding this comment.
No need to .push here, simply assign the reduce method to let ticketPriceTotal, such that let ticketPriceTotal = runners.reduce((ticketSales, runner) =>.....
| // multiplyNums multiplies two numbers and passes the result to the callback. | ||
| cb(x*y); | ||
| } | ||
|
|
There was a problem hiding this comment.
These are all good, but you also should include the invoking of each function, with a callback function that console.logs the result.
|
|
||
| const name = 'Lyle Dylandy'; | ||
| function enroll() | ||
| { |
There was a problem hiding this comment.
This curly brace should be on line 4. This looks like C language style, JS has a few different conventions for code style. Use VS Code with the Prettier extension for automatic formatting on save, this will make your code easier for others (and yourself) to read.
| console.log(`Hello ${name}, you are now ${codeName}.`); | ||
| function sayHi() | ||
| { | ||
| console.log(`Welcome, ${codeName}, to Celestial Being.`); |
| // return param1 + param2; | ||
| // }; | ||
| // add(1,2); | ||
| let add = (x, y) => {return x + y}; |
There was a problem hiding this comment.
Good! When you have it on one line like this, you can also write it as let add = (x, y) => x + y;. When on one line like this you can skip the curly braces {} and the return keyword, as it does that implicitly.
When you use the arrow function on multi lines however you do need the curly braces and return keyword.
No description provided.