Repository navigation
Emmanuel tanifum - #1
Conversation
jamiegoodnight
left a comment
There was a problem hiding this comment.
Yo!
When we run your code for a lot of your array challenges we're getting undefined. I've re-written them for you. You should go over this, compare you code to mine here. See how they're different.
Afterwards, go to repl.it and play around with this practice array:
const test = [{name: "Jamie"}, {name: "Mannnny"}];
It's very small, of course, but map over it, use forEach, etc. Remember "map" needs a return value and forEach doesn't. Also, save these answers as a template that you can refer to, archetypes for each of the array methods.
// ==== 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 = [];
// console.log(fullName);let fullname=runners.forEach(function(x){
console.log(${x.first_name} ${x.last_name});
})console.log(fullname);
// ==== 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 = [];
// console.log(allCaps);let allCaps=runners.map(function(x){
return x.first_name.toUpperCase();
})console.log(allCaps);
// ==== 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 = [];
// console.log(largeShirts);let largeShirts=runners.filter((x)=>{
return x.shirt_size.includes("L");
})console.log(largeShirts);
// ==== 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 = [];
// console.log(ticketPriceTotal);let ticketPriceTotal=[]
const tally=runners.reduce(function(currentTotal, currentDonation){
return currentTotal + currentDonation.donation;
}, 0)ticketPriceTotal.push(tally);
console.log(ticketPriceTotal);
No description provided.