This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var numOfCars = 50; | |
var numOfDrivers = 25; | |
if (numOfCars) { | |
console.log("We have", numOfCars, "to race."); | |
} | |
if (numOfCars < 50) { | |
console.log("never called"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// join( seperator) | |
// seperator is optional, defaults to coma; use "" empty string to combine without spaces. | |
var someArray = ["a", "b", "c", 4, 5, ["bob", "bill"]]; | |
var noSpace; | |
var hyphenated; | |
var commaSpace; | |
noSpace = someArray.join(""); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// splice( starting-index, delete-count, new-item) | |
// start is index exact, delete-count is how many elements to remove including start | |
// new-item is optional and is added at starting-index | |
// splice is permenant | |
var dogs = ["Pit Bull", " American Cocker Spaniel", "Beagle", " Belgian Malinois"]; | |
var newDog = "Bloodhound"; | |
var guideDog = "Brussels Griffon" | |
// take out Beagle | |
dogs.splice(2,1); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var week = ["sun", "mon", "tue", "wed", "th", "fri", "sat"]; | |
var workWeek = []; | |
//we want only mon-fri | |
workWeek = week.slice(1,6); | |
console.log("work week:", workWeek); | |
week[1] = "monday"; | |
console.log("week",week); | |
console.log("work week:", workWeek); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// remember array index starts at zero | |
var rsvps = ["tracy", "bedford", "christina", "nicole", "lisa", "mark", "aaron", "marina"]; | |
var girls = []; | |
console.log("\nnew party rsvps", rsvps); | |
// Pop Quiz: Make a list of girls for the after party using someArray[index] and push | |
// ------ add code below this line-------------------- | |
girls.push( rsvps[0], rsvps[2], rsvps[3], rsvps[4], rsvps[7]); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// remember array index starts at zero | |
var rsvps = ["tracy", "bedford", "christina", "nicole", "lisa", "mark", "aaron", "marina"]; | |
var girls = []; | |
console.log("new party rsvps", rsvps); | |
// Pop Quiz: Make a list of girls for the after party using someArray[index] and push | |
// ------ add code below this line-------------------- | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// to slice to copy part of an array | |
var rsvps = ["julie", "greg", "jess", "nicole", "kenn", "al", "angelina", "boo balm"]; | |
// make a new list for the guys only after party | |
var guys = []; | |
guys.push( rsvps.slice(1,1).join("")); //greg | |
guys.push( rsvps.slice(3,1).join("")); //kenn | |
guys.push( rsvps.slice(3,1).join("")); //al | |
console.log("guys after-party", guys); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var rsvps = ["julie", "greg", "jess", "nicole", "kenn", "al", "angelina", "boo balm"]; | |
console.log("rsvps:", rsvps); | |
// we need to add Dave to the end of party list | |
rsvps.push("dave"); | |
console.log("after adding dave:", rsvps); | |
// julie can't make it, lets take her off the top |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var carList = ["tesla", "bmw", "ford", "kia", "honda"]; | |
// what car is at index 2? | |
console.log("What car is at index 2?", carList[2]); | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var listOfFruit = ["apples", "pear", "lemons", "lychee"]; | |
// what will the # of items be? | |
console.log("I have", listOfFruit.length, "things on my list."); | |