Midterm 1 is Tuesday, March 3rd, 8:00pm-9:30pm
Six days from now!
Conflict signup on course website! MUST sign up by Friday if you have a conflict.
25-35 multiple choice questions
2-4 free response questions
This Sunday (Mar. 1)
3:00pm-5:00pm
1000 Lincoln Hall
Re-do MPs
Re-do Labs
Lecture Examples
Lecture Videos
Practice Midterms
Variables*
Conditionals
For-Loops
Functions
Numbers
Strings (.charAt(), .length, [])
Boolean
Functions
Arrays (.length, [])
Objects (.length)
If you have a variable storing an array, you can use .push(___) to add whatever is the parameter given to the push method to the end of the array.
var arr = []; arr.push(4); // [ 4 ] arr.push("Hi"); // [ 4, "Hi" ] arr.push(9); // [ 4, "Hi", 9 ]
arr.push(arr);
[4, "Hi", 9, [4, "Hi", 9]]
Often, we will want to work with arrays of objects
var receipt = [ { item: "coat", price: 139.99 }, { item: "gloves", price: 44.99 }, { item: "hat", price: 22.54 } ];
var receipt = [ { item: "coat", price: 139.99 }, { item: "gloves", price: 44.99 }, { item: "hat", price: 22.54 } ];
How do we access "gloves"?
Suppose we want to take a 20% discount on items over $50 and return an array of objects where each object returned has the following format:
{ item: "coat", origPrice: 139.99, newPrice: 111.99, discount: 0.2 }
Suppose we now shop around and collect a list of prices for each item:
var receipt = [ { item: "coat", prices: [139.99,129.99,149.99] }, { item: "gloves", prices: [44.99,52.99,39.99] }, { item: "hat", prices: [22.54,39.99,34.99] } ];
Suppose we now want to return an object of arrays with the following format for each object returned:
{ item: "coat", cheapestPrice: 129.99 }