Quiz

  1. I would love to go over arrays-- that tripped me up both in the readings and in the assignment!

    I'd be happy to. Arrays are a sequence of values, indexed by their location in the array.

    
        let kids = ["Ross", "Charlotte"];
        console.log("First kid is ", kids[0]);
        let bigKids = kids.map((k) => k.toUpperCase());
        bigKids.forEach((kid, index) => { console.log(index, ": ", kid) });
    
    
  2. I am still a bit confused about the difference between forEach and map / I'm confused about the forEach method. How is it different from a loop?

    Great question. For map:

    • map takes a function of one argument
    • map invokes that function on every array element
    • map collects all the return values from that function
    • map returns a new array with all the return values

    While forEach:

    • forEach takes a function of one, two or three arguments.
    • forEach invokes that function on every array element, its index, and the array
    • forEach returns no value

    Yeah, forEach takes the place of a loop. The difference is that is a method rather than a syntactic construct.