<|start_filename|>11-04-2020-JSexercises/in-class/introObjects.js<|end_filename|>
let myObject = {
   stuff : "value1",
   nextStuff : "value2"
};

console.log(myObject.stuff);

let a = [1,2,3,4,5];
a[0] = 90; // 90,2,3,4,5

myObject.stuff = "value3";
myObject.thirdStuff = "value4";

console.log(myObject);


<|start_filename|>11-04-2020-JSexercises/in-class/shoppingCart.js<|end_filename|>
// Create an array to represent your shopping
// list with the following items: 'pop tarts', 
// 'ramen noodles', 'chips', 'salsa', and 'coffee'.
let shoppingList = ["pop tarts", "ramen noodles",
                    "chips", "salsa", "coffee"];
                    
// Add 'fruit loops' to the list.
shoppingList.push("fruit loops");
console.log(shoppingList);

// Update 'coffee' to 'fair trade coffee'.
// shoppingList[shoppingList.indexOf("coffee")] = "fair trade coffee;"
shoppingList[4] = "fair trade coffee";
console.log(shoppingList);

// Replace 'chips' and 'salsa' with 'rice' and 'beans'
//shoppingList[2] = "rice";
//shoppingList[3] = "beans";
//shoppingList[2:3] = ["rice", "beans"]; XXX
shoppingList.splice(2, 2, "rice", "beans");
console.log(shoppingList);

// Create an empty array to represent your shopping cart.
let cart = [];

// Remove the last item from your shopping list and add it to your cart.
cart.push(shoppingList.pop());

// Remove the first item from your shopping list and add it to the cart
// shift

// Write a 'while' loop that takes items from your shopping list and moves
// them to your cart until there are no items left on the list.
while(shoppingList.length > 0) {
   cart.push(shoppingList.pop());
}

// sort and reverse
cart.sort().reverse()

// print out
console.log(cart);


<|start_filename|>11-04-2020-JSexercises/run-speed.js<|end_filename|>
// this was a solution to the Application Problem

let startTimes = [5,7,0,10,4];
speeds = [1.4, 1.5, .5, 2, 1.2];
distances = [0,0,0,0,0];

seconds = 40;

for (let i = 0; i < seconds; i++) {
    for (let j = 0; j < startTimes.length; j++) {
        if (i > startTimes[j]) { // implementation based, can be >= also.
            distances[j] += speeds[j];
        }
    }
}

console.log(distances)


<|start_filename|>11-04-2020-JSexercises/in-class/nestedObjects.js<|end_filename|>
let car = {
   engine : {
       type: "v12",
       horsepower: 90000
   },
   suspension : "real strong",
   topSpeed : "c * 1000"
};

let myCarsEngine = car.engine;
myCarsEngine.horsepower;
myCarsEngine.type;


<|start_filename|>11-04-2020-JSexercises/in-class/sliceSplice.js<|end_filename|>
let a =    [1,2,3,4,5]; 
         //0 1 2 3 4
//[2,3,4]
//[1]
//[1,2]

a.slice(1,3); // [2, 3]
a.slice(0,1);
a.slice(4,5);

a[2] = 10;
console.log(a);
//[1, [9, 8, 7, 10, 1000] , 5]
// correct syntax is <array>.splice(<start_index>, <how_many>, <values>...)
a.splice(1, 3, 9, 8, 7, 10, 1000);
console.log(a);


<|start_filename|>11-05-2020/exercises/array_manipulation.js<|end_filename|>
//Arrays and array manipulation: access, sort, reverse.
//<NAME>

/*
Scheduling Chaos
Ellis is trying to manage his senior year schedule. He's currently slated to take the following courses in the following schedule:
     - English
     - Calculus 3
     - Government
     - Economics
     - Environmental Science
     - Anatomy
     - Theater
     - Free Period

His friend Amanda is taking the following classes in the following schedule:
     - English
     - Band
     - Economics
     - Spanish
     - Government
     - Anatomy
     - Calculus 3
     - Free period 

They want to know the following information:
     1. What class do each of them having during second period?
     2. How many classes are they taking together? List them as well (They are in the same class and in the same period)
     3. How many classes to they have in common? (They are in the same class, but not in the same period)
     4. Ellis wants to see his classes in alphabetical order; Amanda wants to see her classes backwards alphabetically
*/




//SOLUTION
//set-up
/*let ellis = ["English", "Calculus 3", "Government", "Economics", "Environmental Science", "Anatomy", "Theater", "Free Period"]
let amanda = ["English", "Band", "Economics", "Spanish", "Government", "Anatomy", "Calculus 3", "Free Period"]

//question 1
console.log("Ellis:", ellis[1])
console.log("Amanda: " + amanda[1])

//question 2
let classesTogether = []
for(let i = 0; i < ellis.length; i++){
     if(ellis[i]==amanda[i]){
          classesTogether.push(ellis[i])
     }
}
console.log(classesTogether.length, "classes together. They are: " + classesTogether)

//question 3
let commonClasses = 0
for(let i = 0; i < ellis.length; i++){
     for(let j = 0; j < amanda.length; j++){
          if(ellis[i]==amanda[j]){
               commonClasses++
          }
     }
}
console.log(`Number of classes in common: ${commonClasses}`)

//question 4
console.log(ellis.sort())
console.log(amanda.sort().reverse())*/

<|start_filename|>11-04-2020-JSexercises/scope-variables.js<|end_filename|>
var s = "some string";
console.log("Answer 1: " + s);

{
        console.log("Answer 2: " + s);
        var s = "a different string";
        console.log("Answer 3: " + s);
}
console.log("Answer 4: " + s);

let a = 5;
console.log("Answer 5: " + a);

{
        // console.log("Answer 6: " + a);
        let a = 10;
        console.log("Answer 7: " + a);
}
console.log("Answer 8: " + a);

// Follow up question, if you change 'let' to 'var' 
// what changes about the above code?

// What happens when you uncomment the line under
// ** SPECIAL LINE ** above. What do you think is
// going on here?


<|start_filename|>11-04-2020-JSexercises/in-class/indexOf.js<|end_filename|>
let myArray = [1,2,3,4,5,4]; // "this is a sentence"

//for (let i = 0; i < myArray.length; i++) {
//    if (myArray[i] === 4) {
//        console.log(i);
//    }
//}

let location = myArray.indexOf(4);
console.log(location);

let drink = ["wine", "rootbeer", "coffee"]; // 0 - (end of array)
if (drink.indexOf("coffee") !== -1) {
   console.log("no drink for me");
}


<|start_filename|>11-05-2020/exercises/scope-variables-commented.js<|end_filename|>
// scope and variable practice
    
// lets define a variable and assign a String to it.
var s = "some string";
console.log("Answer 1: " + s);

//in a new scope, we'll define a new variable with the same name.
{
        console.log("Answer 2: " + s);
        // think hard about what is going on when
        // a variable with the SAME name is
        // redefined here.
        var s = "a different string";
        console.log("Answer 3: " + s);
}
// Did changing the value of s inside a new scope change
// the value of it outside the scope?
console.log("Answer 4: " + s);

let a = 5;
console.log("Answer 5: " + a);

//in a new scope, we'll define a new variable with the same name.
{
        // ** SPECIAL LINE ** 
        // console.log("Answer 6: " + a);

        // think hard about what is going on when
        // a variable with the SAME name is 
        // reassigned here. (note: not redeclared.)
        let a = 10;
        console.log("Answer 7: " + a);
}
// Answer 7 may suprise you.
console.log("Answer 8: " + a);

// Follow up question, if you change 'let' to 'var' 
// what changes about the above code?

// What happens when you uncomment the line under
// ** SPECIAL LINE ** above. What do you think is
// going on here?


<|start_filename|>11-04-2020-JSexercises/in-class/switch.js<|end_filename|>
let x = 1;
switch(x) {
case 3:
    console.log('three')
    break;
case 1:
    console.log(1);
    break;
case 2:
    console.log(2);
    break;
case 1000:
    console.log("I shouldn't be evaluated, but I am."); 
    // above break statements protect us from cascading 
    // try removing the above break statements
    break;
default:
    console.log('default');
}

let word = "Apple";
switch(x) {
case 'p':
    // make letter 'P'
    break;
default:
    console.log('default');
}
console.log(word[0]);



<|start_filename|>11-04-2020-JSexercises/in-class/splitJoin.js<|end_filename|>
let a = "This is a sentence with some words in it sentence.";
let b = a.split(' '); //delimiter
console.log(b);

// make a function that tells me how many words are 
// in a sentence
console.log(b.length);
b[2] = "buttercups";
console.log(b);
let c = b.join(' ');
console.log(c);

console.log(c); // console.log(c.toString())


<|start_filename|>11-04-2020-JSexercises/in-class/forEach.js<|end_filename|>
// let teachers = [1,2,3,4,5];

// for (let i = 0; i < teachers.length; i++) {
//     console.log(teachers[i], i)
// }

// teachers.forEach(function(item, index) {
//     console.log("Index: " + index);
//     console.log(item, index);
// });

let stuff = ['word1', 'not a word', 'bunny'];
stuff.forEach(function(item, index) {
    console.log(item);
    if (item === 'bunny') {
        console.log(index);
    }
});


<|start_filename|>11-04-2020-JSexercises/conditionals-commented.js<|end_filename|>
//conditional practice

// a basic if statement, it runs the code inside the
// {} when the (condition) is true.
let iAmTrue = true;
if (iAmTrue) {
        console.log("True Test")
}

// a layered if statement
if (false) {
        console.log("This will never run.")
} else { 
        // we run what is in the  "else" block because the main
        // 'if' statement condition evaluated to false.
        console.log("This will always run")
}


<|start_filename|>11-04-2020-JSexercises/in-class/sortReverse.js<|end_filename|>
let a = [1,3,5,2,6,5];
a.sort();
console.log(a);
a.reverse();
console.log(a);
let b = ['Z', 'c', 'y', 'aWordb', 'aWordB', 'aWordA', 'z']; // & % $
// ascii number tables
// 'a' -> 97
// 'A' -> 65
b.sort();
console.log(b);


<|start_filename|>11-03-2020-JS/BevBurger.js<|end_filename|>
    // let bevs = ["water", "coffee", "juice", "hot tea"];

    // for (let i = 0; i < 4; i++) { // 0, 1, 2, 3
    //     console.log(i);
    //     console.log(bevs[i]);
    // }
    
    // bevs.push("hot chocolate");
    // bevs.push("wine");
    
    // let order = "wine";
    // let myDrinkWasServed = false;
    // for (let i = 0; i < bevs.length; i++) { // 0, 1, 2, 3
    //     console.log("Is your beverage: " + bevs[i]);
    //     if (order === bevs[i]) {
    //         console.log("Here is your order, I hope you enjoy your drink: " 
    //                     + bevs[i]);
    //         myDrinkWasServed = true;
    //         break;
    //     }
    // }
    // if (!myDrinkWasServed) { // !true === false
    //     console.log("aw shucks no drink for me.")
    // }
    
    let burger = [];
    burger.push("bread");
    for (let i = 0; i < 9; i++) {
        burger.push("");
    }
    burger.push("bread");
    
    console.log(burger);
    let baconBurger = ["patty", "bacon", "cheese"];// 0 - 2 , 3, i<3, 0,1,2
    let vegBurg = ["lettuce", "vegPatty", "tomato"];
    
    let buildBurg = vegBurg;
    for (let j = 0; j < buildBurg.length; j++) { // 0 - 2
        for (let i = 0; i < buildBurg.length; i++) { // 1 - 3 , 0 - 2
                console.log("We are grabbing our " + buildBurg[i]);
                console.log("We are placing it in " + ((j*3)+(i+1)));
                burger[(j*3)+(i+1)] = buildBurg[i]; // 1 2 3, // 4,5,6 // 7,8,9
                                                      // 0 * 3,    1 * 3,   2 * 3
        }
    }
    console.log(burger);
    
