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
47 changes: 42 additions & 5 deletions assignments/array-methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,23 +54,60 @@ const runners = [{"id":1,"first_name":"Charmain","last_name":"Seiler","email":"c
{"id":50,"first_name":"Shell","last_name":"Baine","email":"[email protected]","shirt_size":"M","company_name":"Gabtype","donation":171}];

// ==== 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.
// 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 = [];
findrunner();
console.log(fullName);
function findrunner(){
runners.forEach(function(i) {
fullName.push(i.first_name+" "+i.last_name);


});
JSON.stringify(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 v = [];
allCapsMeth()
console.log(v);
function allCapsMeth(){
runners.forEach(function(i) {
let result = i.first_name

allCaps.push(result);


});
v.push(allCaps.map(x => x.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((shirts)=> {
return shirts.shirt_size ==="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 = [];

let ticketPriceTotal = 0;
let result=[];
for (var i = 0; i < runners.length; i++) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Try not to use var

result.push(runners[i].donation);
}
ticketPriceTotal = result.reduce(
( accumulator, currentValue ) => accumulator + currentValue,
0
);
console.log(ticketPriceTotal);

// ==== Challenge 5: Be Creative ====
Expand All @@ -80,4 +117,4 @@ console.log(ticketPriceTotal);

// Problem 2

// Problem 3
// Problem 3
11 changes: 11 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<html>
<head>

- <title>Page Title</title>
+ <script type="text/javascript" src="assignments\callbacks.js"></script>
+ <script type="text/javascript" src="assignments\array-methods.js"></script>
<script type="text/javascript" src="assignments\closure.js"></script>
<script type="text/javascript" src="assignments\function-conversion.js"></script>
+ <title>Page Title</title>
</head>
<body>