Skip to content

Commit 7c6ab12

Browse files
committed
Finished main tasks
1 parent f004ace commit 7c6ab12

3 files changed

Lines changed: 44 additions & 6 deletions

File tree

assignments/array-methods.js

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -457,10 +457,15 @@ const runners = [
457457

458458
// ==== Challenge 1: Use .forEach() ====
459459
// 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.
460-
let fullName = runners.forEach(function(item){
461-
return item;
460+
// let fullName = runners.forEach(function(item){
461+
// return item;
462+
// });
463+
let fullName = [];
464+
runners.forEach(function(item) {
465+
fullName.push(`${item.first_name} ${item.last_name}`);
462466
});
463467

468+
464469
console.log(fullName);
465470

466471
// ==== Challenge 2: Use .map() ====
@@ -483,9 +488,32 @@ console.log(ticketPriceTotal);
483488

484489
// Problem 1
485490
// The director wants to play tricks on the runners. Change all shirt sizes from large to small and list their info.
491+
let changedShirts = [];
492+
let placeholder = {};
493+
largeShirts.forEach(function(item) {
494+
placeholder = Object.assign({}, item);
495+
// new way of doing the same thing on line 494
496+
// placeholder = {...item};
497+
placeholder.shirt_size = "S";
498+
changedShirts.push(placeholder);
499+
});
500+
console.log(changedShirts);
486501

487502
// Problem 2
488-
// The director has decided to steal from the donations. Take away half of each runner's donation.
503+
// The director has decided to steal from the donations. Take away half of each runner's donation.
504+
let newDonations = runners.map(item => item.donation / 2);
505+
console.log(newDonations);
489506

490507
// Problem 3
491-
// The director has completely lost his mind. Change every runner's name to "EATS DIRT", make each company name upper case, and remove all of their emails.
508+
// The director has completely lost his mind. Change every runner's name to "EATS DIRT", make each company name upper case, and remove all of their emails.
509+
let runnersCopy = {};
510+
let copyArray = [];
511+
runners.forEach(function(item) {
512+
runnersCopy = Object.assign({}, item);
513+
runnersCopy.first_name = "EATS";
514+
runnersCopy.last_name = "DIRT";
515+
runnersCopy.company_name = item.company_name.toUpperCase();
516+
runnersCopy.email = '';
517+
copyArray.push(runnersCopy);
518+
});
519+
console.log(copyArray);

assignments/closure.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,21 @@
11
// ==== Challenge 1: Write your own closure ====
22
// Write a simple closure of your own creation. Keep it simple!
3+
function parent(){
4+
let name = "dad";
5+
function child(){
6+
//name=="dad" is in the closure here
7+
}
8+
}
39

4-
10+
let count = 0;
511
// ==== Challenge 2: Create a counter function ====
612
const counter = () => {
713
// Return a function that when invoked increments and returns a counter variable.
14+
return count++;
815
};
16+
17+
console.log(counter());
18+
console.log(counter());
919
// Example usage: const newCounter = counter();
1020
// newCounter(); // 1
1121
// newCounter(); // 2

assignments/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<html>
33

44
<head>
5-
<script src="callbacks.js"> </script>
5+
<script src="array-methods.js"> </script>
66
</head>
77

88
<body>

0 commit comments

Comments
 (0)