From b952bed5f521ee8f296a92b4635accacbf9fd469 Mon Sep 17 00:00:00 2001 From: Josh Aragon Date: Wed, 2 Sep 2020 20:23:57 -0600 Subject: [PATCH 1/8] Add day 1 --- day_1/exercises/booleans.js | 6 +++--- day_1/exercises/concatenation.js | 10 +++++----- day_1/exercises/numbers.js | 10 +++++----- day_1/exercises/strings.js | 6 +++--- day_1/exercises/variables.js | 10 +++++----- day_1/questions.md | 10 ++++++++++ 6 files changed, 31 insertions(+), 21 deletions(-) diff --git a/day_1/exercises/booleans.js b/day_1/exercises/booleans.js index cd71268f8..a88062611 100644 --- a/day_1/exercises/booleans.js +++ b/day_1/exercises/booleans.js @@ -1,6 +1,6 @@ /* In the exercises below, write your own code where indicated -to achieve the desired result. +to achieve the desired result. A few are done for you already. @@ -18,7 +18,7 @@ console.log(typeof (1 == 1)); console.log(1 == 2); // example: log to the console the result of 7 is not equal to 2: -console.log(/*your code here*/); +console.log(7 !== 2); // example: log to the console the result of "hello" is equal to "Hello": - +console.log("hello" == "Hello") diff --git a/day_1/exercises/concatenation.js b/day_1/exercises/concatenation.js index 9b46b2b82..332c54fed 100644 --- a/day_1/exercises/concatenation.js +++ b/day_1/exercises/concatenation.js @@ -1,6 +1,6 @@ /* In the exercises below, write your own code where indicated -to achieve the desired result. +to achieve the desired result. A few are completed for you, to provide an example. @@ -14,8 +14,8 @@ var team = "Chudley Cannons"; console.log("The " + team + " are " + name + "'s favorite Quidditch team"); -// What happens if you include other data types when you use concatination? What data type is logged after we run this code? -// ANSWER to question on line 17: +// What happens if you include other data types when you use concatination? What data type is logged after we run this code? All the code is combined, and is output into a string data type. +// ANSWER to question on line 17: var number = 7; var creatures = "unicorns"; @@ -27,7 +27,7 @@ console.log("My zoo has " + number + " " + creatures + "!") var speedy = "quick red fox"; var slowPoke = "lazy brown dog"; -console.log(/*YOUR CODE HERE*/); +console.log("The " + speedy + " jumped over the " + slowPoke); // Write code that combines the variables below into a string that // reads "In a predictable result, the tortoise beat the hare!" @@ -36,4 +36,4 @@ console.log(/*YOUR CODE HERE*/); slowPoke = "tortoise"; speedy = "hare"; - // YOUR CODE HERE +console.log("In a predictable result, the " + slowPoke + " beat the " + speedy); diff --git a/day_1/exercises/numbers.js b/day_1/exercises/numbers.js index c88e9da86..fe4c69799 100644 --- a/day_1/exercises/numbers.js +++ b/day_1/exercises/numbers.js @@ -8,18 +8,18 @@ file from your terminal with the command `node day_1/exercises/numbers.js` console.log(2 + 2); // log the result of 7 subtracted from 83 console: -console.log(/*YOUR CODE HERE*/); +console.log(7 - 83); // log the result of 6 multiplied by 53 to the console: -// YOUR CODE HERE +console.log(6 * 53); // log the result of 20 divided by 4 to console: -// YOUR CODE HERE +console.log(20 / 4); // log the result of the modulo of 10 into 54: -// YOUR CODE HERE +console.log( 54 % 10); // log the total number of snacks to the console, using the variables below: var healthySnackCount = 7; var junkFoodSnackCount = 4; -// YOUR CODE HERE +console.log(healthySnackCount + junkFoodSnackCount); diff --git a/day_1/exercises/strings.js b/day_1/exercises/strings.js index 0b43b8701..23198cbf5 100644 --- a/day_1/exercises/strings.js +++ b/day_1/exercises/strings.js @@ -8,10 +8,10 @@ file from your terminal with the command `node day_1/exercises/strings.js` console.log("Alan Turing"); // Write code below to log `Welcome to Turing!` in the console: -console.log(/*YOUR CODE HERE*/); +console.log("Welcome to Turing!"); // Write code below to log `99 bottles of pop on the wall...`: -// YOUR CODE HERE +console.log("99 bottles of pop on the wall..."); //Write code below to log one line from your favorite song or movie: -// YOUR CODE HERE +console.log("Some nights I wish I could go back in life not to change sh*t, just to feel a couple things twice") diff --git a/day_1/exercises/variables.js b/day_1/exercises/variables.js index 8e731eea0..ae44c9e3c 100644 --- a/day_1/exercises/variables.js +++ b/day_1/exercises/variables.js @@ -9,19 +9,19 @@ console.log(name); // Write code below to assign the string 'Dobby' to a variable and // log that variable to the console: var houseElf = "Dobby"; -// YOUR CODE HERE +console.log(houseElf); // Write code below to save the string 'Harry Potter must not return to Hogwarts!' // log that variable to the console: -// YOUR CODE HERE - +var notReturn = "Harry Potter must not return to Hogwarts!" +console.log(notReturn) // example: Write code below to add 2 to the variable `students` and // log the result: var students = 22; -// YOUR CODE HERE +students = 24; console.log(students); // Write the code below to subtract 2 students from the `students` variable and // log the result: -// YOUR CODE HERE +students = 22; console.log(students); diff --git a/day_1/questions.md b/day_1/questions.md index 4fa4f6a12..487a8fc54 100644 --- a/day_1/questions.md +++ b/day_1/questions.md @@ -1,13 +1,23 @@ ## Day 1 Questions 1. How would you log the string `"Hello World!"` to the console? +var helloWorld = "Hello World!" +console.log(helloWorld); 1. What is the character you would use to indicate comments in a JavaScript file? +// Backslash 1. Explain the difference between an integer and a floating-point number? +Interger is all whole numbers (positive and negative). floating-point numbers are any decimal numbers. 1. In the space below, create a variable `animal` that holds the string `"zebra"`. +var animal = "zebra" 1. How would you log the string `"zebra"` using the variable that you created above? +console.log(animal); 1. What is concatenation? Use concatenation to log a sentence to the console using the variable `animal`. +It is adding things together. +var favoriteAnimal = "My favorite animal is a" + animal; +console.log(favoriteAnimal) +// this will log the string "My favorite animal is a zebra" From 4d51ff505f04fbf80a347f0746da0db40c9e3f2d Mon Sep 17 00:00:00 2001 From: Josh Aragon Date: Sun, 6 Sep 2020 17:31:16 -0600 Subject: [PATCH 2/8] Add Day 2 Work --- day_2/arrays_methods.md | 7 +++++++ day_2/exercises/array.js | 27 ++++++++++++++------------- day_2/exercises/comparisons.js | 16 ++++++++-------- day_2/exercises/iteration.js | 14 ++++++++++---- day_2/exercises/loops.js | 6 ++++-- day_2/questions.md | 11 +++++++++++ 6 files changed, 54 insertions(+), 27 deletions(-) create mode 100644 day_2/arrays_methods.md diff --git a/day_2/arrays_methods.md b/day_2/arrays_methods.md new file mode 100644 index 000000000..b57f7ec33 --- /dev/null +++ b/day_2/arrays_methods.md @@ -0,0 +1,7 @@ +The pop() method removes the last element in the array. + +The push() method adds new items to the end of the array. + +shift() removes the 0th element from the array. + +unshift() will add new elements to the beginning of an array. diff --git a/day_2/exercises/array.js b/day_2/exercises/array.js index 12efb686d..51fcf2db3 100644 --- a/day_2/exercises/array.js +++ b/day_2/exercises/array.js @@ -10,7 +10,7 @@ var animals = ["Zebra", "Giraffe", "Elephant"]; console.log(animals); // Declare a variable that will store an an array of at least 3 foods (strings) -// YOUR CODE HERE +var food = ["Wings", 'Pizza', "Hamburger"]; // example: Write code below that will log the number of elements in array of // animals from above. @@ -18,28 +18,29 @@ console.log(animals.length); // Write code below that will log the number of elements in the array of // foods from above. -// YOUR CODE HERE +console.log(food.length); // Write code below that will log "Zebra" from the animals array -// YOUR CODE HERE +var firstElement = animals.shift() +console.log(firstElement); // Write code using bracket notation that will log the first item in the animals array -// YOUR CODE HERE +console.log(animals[0]); // Write code using bracket notation that will log the last item in the animals array -// YOUR CODE HERE - +console.log(animals[animals.length - 1]); // Write code using bracket notation that will reassign the last item in the animals // array to "Gorilla" -// YOUR CODE HERE - +animals.splice(2, 1, 'Gorilla'); +console.log(animals); // Write code below that will log the last item from the foods array. -// YOUR CODE HERE - +console.log(food.pop()); // Write code below that uses a method to add "lion" to the animals array and // log the changed array to verify "lion" has been added -// YOUR CODE HERE - +animals.push("Lion"); +console.log(animals); // Write code below that removes the last item of food from the foods array and // log the cahnged array to verify that item has been removed -// YOUR CODE HERE +food.pop(); + +console.log(food); diff --git a/day_2/exercises/comparisons.js b/day_2/exercises/comparisons.js index 35a84273b..710ca2ce9 100644 --- a/day_2/exercises/comparisons.js +++ b/day_2/exercises/comparisons.js @@ -13,10 +13,10 @@ var fourthVar = 0; console.log(firstVar > secondVar); // this should return: false // log the result of the comparison: is firstVar less than secondVar? -console.log(); // this should return: true +console.log(firstVar < secondVar); // this should return: true // log the result of the comparison: is firstVar equal to thirdVar? (use the == operator) -console.log(); // this should return: true +console.log(firstVar == thirdVar); // this should return: true /* Note: this is an example of type coercion. Although thirdVar is a string and secondVar is an integer, @@ -25,7 +25,7 @@ perform this evaluation */ // log the result of the comparison: is firstVar strictly equal to thirdVar? (use the === operator) -console.log(); // this should return: false +console.log(firstVar === thirdVar); // this should return: false /* Note: the strictly equal to operator compares the value of the variable in addition to the type of the variable. @@ -34,19 +34,19 @@ the comparison still evaluates to false. */ // log the result of the comparison: is firstVar not equal to secondVar? -console.log(); // this should return: true +console.log(firstVar !== secondVar); // this should return: true // log the result of the comparison: is secondVar greater than or equal to 20? -console.log(); // this should return: true +console.log(secondVar >= 20); // this should return: true // log the result of the comparison: is secondVar greater than or equal to 21? -console.log(); // this should return: false +console.log(secondVar >= 21); // this should return: false // log the result of the comparison: is secondVar less than or equal to 20? -console.log(); // this should return: true +console.log(secondVar <= 20); // this should return: true // log the result of the comparison: is secondVar less than or equal to 21? -console.log(); // this should return: true +console.log(secondVar <= 21); // this should return: true // log the result of the comparison: is 0 equal to true? console.log(0 == true) // this should return: false diff --git a/day_2/exercises/iteration.js b/day_2/exercises/iteration.js index 4b18552ea..533a10c2a 100644 --- a/day_2/exercises/iteration.js +++ b/day_2/exercises/iteration.js @@ -16,13 +16,19 @@ for (var i = 0; i < animals.length; i++) { // is awesome!" for each animal. for (var i = 0; i < animals.length; i++) { - // YOUR CODE HERE + console.log("The " + animals[i] +" is awesome!"); } // Create an array of foods and then iterate over that array to log "Add // to shopping list" for each food item. -// YOUR CODE HERE - +var foods = ["apple", "cheese", "chicken", "blue berries", "watermelon"]; +for (var i = 0; i< foods.length; i++) { + console.log("Add " + foods[i] + " to shopping list" ) +}; // Create an array of numbers and then iterate over that array to log doubles // of each of the number. -// YOUR CODE HERE +var numbers =[7, 4, 68, 79, 32, 17]; + +for(var i = 0; i< numbers.length; i++) { + console.log(numbers[i] *2); +} diff --git a/day_2/exercises/loops.js b/day_2/exercises/loops.js index 22c60d895..3cb6886fb 100644 --- a/day_2/exercises/loops.js +++ b/day_2/exercises/loops.js @@ -8,10 +8,12 @@ for (var i = 0; i < 5; i++) { // Write code below that logs to the console the sum of 2 plus 2 7 times: for (var i = 0; i < 7; i++) { - // YOUR CODE HERE + console.log(2 + 2) } // Write code below that prints the phrase 'She sells seashells down by the seashore' // 10 times. - // YOUR CODE HERE +for (var i = 0; i<10; i++) { + console.log("She sells seashells down by the seashore") +} diff --git a/day_2/questions.md b/day_2/questions.md index b3594228b..24e3306b2 100644 --- a/day_2/questions.md +++ b/day_2/questions.md @@ -1,15 +1,26 @@ ## Day 2 Questions 1. Declare a variable named `animals` that stores an array containing the following strings: `"zebra", "giraffe", "elephant"`. +var animals = ["zebra", "giraffe", "elephant"]; 2. Using the array `animals`, how would you access `"giraffe"`? +console.log(animals[1]); 3. How would you add `"lion"` to the `animals` array? +animals.push("lion"); 4. Name and describe two additional array methods. +The push method adds an element to the end of an array. + +The pop method will remove the last element of an array and log that same element. 5. What are the boolean values in JavaScript? +true or false 6. In JavaScript, how would you evaluate if `2` is equal to `25`? What is the result of this evaluation? +console.log(2 == 25) +false 7. In JavaScript, how would you evaluate if `25` is greater than `2`? What is the result of this evaluation? +console.log(25 < 2) +false From e87dd84a3d6d40c6adce4afd3265531948513876 Mon Sep 17 00:00:00 2001 From: Josh Aragon Date: Sun, 6 Sep 2020 19:31:43 -0600 Subject: [PATCH 3/8] Add Day 3 Work --- day_3/exercises/decision-making.js | 7 +++++++ day_3/exercises/if-statements.js | 23 +++++++++++++++++++---- day_3/questions.md | 13 ++++++++++++- 3 files changed, 38 insertions(+), 5 deletions(-) diff --git a/day_3/exercises/decision-making.js b/day_3/exercises/decision-making.js index 10ebc14d6..0eb44d9cf 100644 --- a/day_3/exercises/decision-making.js +++ b/day_3/exercises/decision-making.js @@ -40,16 +40,23 @@ if (bearChoice === 1) { /* Reflection Questions 1. In English, using technical vocabulary, describe what is happening between lines 17 and 21. +We are using an if/else statement. If line 17 returns true bearClothing will be assigned "hat", if false "scarf" will be assigned to bearClothing. 2. What variable has a new value assigned to it after the first if statement executes? +bearChoice is assigned a new value after the first if statement executes. 3. If you changed the variable doorChoice to equal 3, what would the bearClothing value be? +The value would be bearClothing = "scarf". The outcome of hat is only possible when doorChoice is equal to 1. 4. In English, using technical vocabulary, describe what is happening between lines lines 31 and 38. +The outcomes of each door is shown on lines 31-38. If door 1 is chosen he shows you a way out. If 2, the bear begins to cry. If 3. You run into the next room which is full of snakes. 5. If you changed the variable bearChoice to equal 3, what will be the final outcome be? +The outcome would be "You run as fast as you can into the next room. It's full of snakes!" 6. If you changed the variable doorChoice to equal 1, and the variable bearChoice to equal 2, what will be the final outcome be? +You tell the bear the "hat" is too small and it starts to cry! 7. What is your favorite ending? +I like the ending of running into the snakes, its exciting and scary! */ diff --git a/day_3/exercises/if-statements.js b/day_3/exercises/if-statements.js index a53f508d7..bb8e1b6f9 100644 --- a/day_3/exercises/if-statements.js +++ b/day_3/exercises/if-statements.js @@ -11,7 +11,7 @@ with you to be prepared based on the following conditions: if it is icy, log "yak traks" */ -var weather = 'snowy'; +var weather = 'sunny'; if (weather == 'sunny') { console.log("sunscreen"); @@ -46,9 +46,16 @@ When numQuarters = 3, program should log "I have enough money for a gumball" */ var numQuarters = 0; - -console.log("I have enough money for a gumball"); -console.log("I don't have enough money for a gumball"); +numQuarters = 1 +if (numQuarters == 0) { + console.log("I don't have enough money for a gumball"); +} else if (numQuarters == 1) { + console.log("I don't have enough money for a gumball"); +} else if (numQuarters == 2) { + console.log("I have enough money for a gumball"); +} else { + console.log("I have enough money for a gumball"); +} /* ---------------------------- Using the variables defined below, determine if you have the @@ -64,3 +71,11 @@ When cupsOfFlour = 3 and hasSauce = true, your program should log "I can make pi var cupsOfFlour = 1; var hasSauce = true; + +if (cupsOfFlour == 1){ + console.log("I cannot make pizza"); +}else if (cupsOfFlour >+2 && hasSauce == true){ + console.log("I can make pizza"); +}else if (cupsOfFlour >= 2 && hasSauce =- false){ + console.log("I cannot make pizza") +} diff --git a/day_3/questions.md b/day_3/questions.md index d67412a90..6f7f6cd00 100644 --- a/day_3/questions.md +++ b/day_3/questions.md @@ -1,13 +1,24 @@ ## Day 3 Questions 1. What is a conditional statement? Give one example of a daily life conditional. Give one example of where a conditional is probably used in a web application you use. +A conditional statement is in if/then format, when a certain condition is met, then a result is returned. If a the condition is not met, a different result while return. + +One conditional of my daily life is. Go to work, if i fail that task the result would be get fired. A web app conditional is entering my password. If i enter it correctly i sign in, if false the result would be "password incorrect" 2. Why might you want to use an `if` statement? +If I wanted to make a condition confirmed I would use a "if" statement. 3. What is the JavaScript syntax for an `if` statement? +if (condition){ +function results +} 4. How do you add multiple conditions to an `if` statement? +You would use else if and else to use multiple conditions. 5. What is the JavaScript syntax for an `if/else` statement? - +if (condition) { + // block of code to be executed if the condition is true +} 6. Other than an `if` statement, can you think of any other ways we might want to use a conditional statement? +We can use conditional statements to loop until the condition is not met. From a6c0986d238d9dfaf6015bcf7b8224659a41be39 Mon Sep 17 00:00:00 2001 From: Josh Aragon Date: Mon, 7 Sep 2020 17:31:55 -0600 Subject: [PATCH 4/8] Add Day 4 Work --- day_4/exercises/functions-and-variables.js | 6 +++--- day_4/exercises/functions.js | 16 ++++++++++++---- day_4/questions.md | 13 ++++++++++++- 3 files changed, 27 insertions(+), 8 deletions(-) diff --git a/day_4/exercises/functions-and-variables.js b/day_4/exercises/functions-and-variables.js index 2bfefc354..3fb28dfcd 100644 --- a/day_4/exercises/functions-and-variables.js +++ b/day_4/exercises/functions-and-variables.js @@ -27,7 +27,7 @@ console.log("ourNumber value outside scopedFunction: " + ourNumber); What's the value of ourNumber? Still 5, because function definitions create their own scope that's entirely outside of the execution flow. If we move the console log into the scopedFunction... */ - +/* var ourNumber = 5; function scopedFunction() { @@ -49,7 +49,7 @@ does not alter the argument that is passed into it. Let's say we have a variable ourArray that stores an array. We'll cover arrays in more depth later as well but for now just remember our earlier explanation of arrays as ordered lists. Run this code to see the result. */ - +/* function getLastValue(functionArray) { console.log("The value of the last index in my array is: " + functionArray[2]); }; @@ -68,7 +68,7 @@ because using bracket notation to get a value from an array does not mutate the There are techniques that will perform some action on the argument that mutates the caller. We can in fact permanently alter variables outside the function definition's scope. */ - +/* function getLastValue(functionArray) { console.log("The value of the last index in my array is: " + functionArray.pop()); }; diff --git a/day_4/exercises/functions.js b/day_4/exercises/functions.js index 858b4aa62..4dcb169be 100644 --- a/day_4/exercises/functions.js +++ b/day_4/exercises/functions.js @@ -14,17 +14,25 @@ printName(); // Update the function below so that it takes an argument of your name and // prints your name -function printName() { // hint.. add a parameter on this line :) - // YOUR CODE HERE +function printName() { +console.log(name); }; -printName("Albus Dumbledore"); +printName("Shaemus Nevin"); // Write a function that takes in 2 numbers as arguments and prints their sum, and // then call that function. -//YOUR CODE HERE +function sum(num1, num2) { + console.log(num1 + num2) +} +sum(7, 25); // Write a function that takes in two strings and prints a concatenation // of those two strings, for example the arguments could be ("Oscar", "Ruck") and // the end result might be "Oscar and Ruck are BFFS". Then, call that function. // YOUR CODE HERE +function theBoys(dude1, dude2){ + console.log(dude1 + " and " + dude2 + " are brothers from another mother.") +} + +theBoys(Zach, Matt) diff --git a/day_4/questions.md b/day_4/questions.md index 66cc7417e..d5cfde2c8 100644 --- a/day_4/questions.md +++ b/day_4/questions.md @@ -1,15 +1,26 @@ ## Day 4 Questions 1. In your own words, what is the purpose of a function? +A function take multiple data types and will combine them into 1 simpler output. This saves a lot of time by being able to simply type out the function name as a variable instead of rewriting the whole block of code again. -2. What is a parameter? +2. What is a parameter? +A parameter is the variable that you input into a function that will vary the outcome of said function. 3. What is a return value? +A return value is the output/code logged after the function has been ran. 4. In the space below, declare a function named `hello` that will print to the console, `"Sam I am"`. +function hello(){ + console.log("Sam I am") +}; 5. Declare a function name `helloSomeone` that takes an argument of `name` and logs `name + " I am"`. +function helloSomeone(name){ + console.log(name + " I am") +}; 6. How would you _call_ or _execute_ the function that you created above? +helloSomeone(Joshua) 7. What questions do you still have about functions in JavaScript? + Could we just use a loop instead of a function? From 906aa83f288b3a8a96d27d08f96ac1f059a5cf3e Mon Sep 17 00:00:00 2001 From: Josh Aragon Date: Mon, 7 Sep 2020 19:15:30 -0600 Subject: [PATCH 5/8] Add Day 5 Work --- day_5/exercises/objects.js | 23 ++++++++++++++++------- day_5/questions.md | 13 +++++++++++++ 2 files changed, 29 insertions(+), 7 deletions(-) diff --git a/day_5/exercises/objects.js b/day_5/exercises/objects.js index b747397b4..f0a78180c 100644 --- a/day_5/exercises/objects.js +++ b/day_5/exercises/objects.js @@ -4,6 +4,7 @@ to achieve the desired result. You should be able to run this file from your terminal with the command `node day_5/exercises/objects.js` */ +// example: Write code below to print an object that holds grocery store inventory // example: Write code below to print an object that holds grocery store inventory var foods = { apples: 23, @@ -15,18 +16,26 @@ console.log(foods); // Write code below that will print an B=Object of animals and the number // of that type of animal at the zoo. (an inventory of animals) -var zoo = // YOUR CODE HERE -console.log(zoo) +var zoo = { + penguin: 14, + lion: 3, + tigers: 5, + monkeys: 17, + kangaroo: 8, +}; + + +console.log(zoo); // Using the zoo that you created above, print all the keys in the Object. -// YOUR CODE HERE +console.log(Object.keys(zoo)); // Using the zoo that you created above, print all the values in the Object. -// YOUR CODE here - +console.log(Object.values(zoo)); // Using the zoo that you created above, print the value of the first item in // the Object -// YOUR CODE HERE +console.log(zoo.penguin); // Add an animal to the zoo Object and print the updated Object. -// YOUR CODE HERE +zoo.parrot = 6, +console.log(zoo); diff --git a/day_5/questions.md b/day_5/questions.md index 49c68852c..9b633d76e 100644 --- a/day_5/questions.md +++ b/day_5/questions.md @@ -1,13 +1,26 @@ ## Day 5 Questions 1. What is an Object, and how is it different from an Array in Javascript? +An object is a variable that holds multiple lines of data. An array doesn't differentiate data types its just a line of different elements, an object has different data with different values on each line. 2. In the space below, create an Object stored to a variable named `petStore`. This Object should hold an inventory of items and the number of that item that you might find at a pet store. +var petStore = { + +dogToy: 25, +catToy: 20, +fishFood: 40, +dogFood: 50, +leash: 35, +}; 3. Given the following `states = {"CO": "Colorado", "IA": "Iowa", "OK": "Oklahoma"}`, how would you access the value `"Iowa"`? +states.IA = "Iowa" 4. How would you add a new property to that Object with a key of `"MN"` and a value of `"Minnesota"`? +states.MN = "Minnesota" 5. What is another example of when we might use a Object? In this case, why is an Object better than an Array? +When we want to store specific data tied to a certain element. An array is great for writing a group of items, but if we want detailed information about each of those items that when an Object shines. 6. What questions do you still have about Objects? +I feel like I got a grasp of this concept pretty well and quickly. If I had to ask something though it would be is there a limit for the amount of properties an object can have? When should I use bracket notation instead of dot notation? Only when accessing a string? From 8200bd7a32e7ff50422a428b59d3d7984cbf4a1a Mon Sep 17 00:00:00 2001 From: Josh Aragon Date: Tue, 8 Sep 2020 21:25:46 -0600 Subject: [PATCH 6/8] Add Day 6 Work --- day_6/exercises/burrito.js | 23 ++++++++++++++++++++++- day_6/exercises/dog.js | 6 ++++++ day_6/exercises/person.js | 23 ++++++++++++++++++++++- day_6/questions.md | 30 ++++++++++++++++++++++++++++++ 4 files changed, 80 insertions(+), 2 deletions(-) diff --git a/day_6/exercises/burrito.js b/day_6/exercises/burrito.js index b01747cda..b4bd76623 100644 --- a/day_6/exercises/burrito.js +++ b/day_6/exercises/burrito.js @@ -16,11 +16,32 @@ class Burrito { this.base = base; this.toppings = toppings; } + + +addTopping(topping){ + this.toppings.push(topping) +} + + removeTopping(topping) { + var removed = this.toppings.indexOf(topping) + if (removed > -1) { + this.toppings.splice(removed, 1) + } + } + +changeProtein(newProtein){ + this.protein = newProtein +} }; + + + var dinner = new Burrito("Beans", "Rice", ["cheese", "salsa", "guacamole"]); -// Call the methods here +dinner.addTopping("green chili") +dinner.removeTopping("guacamole"); +dinner.changeProtein("Chicken") console.log(dinner.protein); console.log(dinner.base); diff --git a/day_6/exercises/dog.js b/day_6/exercises/dog.js index b8d254e28..688a88974 100644 --- a/day_6/exercises/dog.js +++ b/day_6/exercises/dog.js @@ -23,6 +23,10 @@ class Dog { eat() { this.hungry = false; } + + play(){ + this.hungry = true; + } } var fido = new Dog("Bernese", "Fido", 4) @@ -32,3 +36,5 @@ console.log(fido.age); console.log(fido.hungry); fido.eat(); console.log(fido.hungry); +fido.play(); +console.log(fido.hungry); diff --git a/day_6/exercises/person.js b/day_6/exercises/person.js index 4f3519eb4..0aafc8c88 100644 --- a/day_6/exercises/person.js +++ b/day_6/exercises/person.js @@ -8,4 +8,25 @@ person methods below the class so that they print their result to the terminal. */ -// YOUR CODE HERE +class Person{ + constructor(age, height){ + this.age = age; + this.height = height; + this.playsGames = true; + this.isAngry = false; + } + +playGame(){ + this.playsGames = true; +} +loseMatch(){ + this.isAngry = true; + } +}; +var joeMama = new Person("Jen", "4'11"); + +console.log(joeMama); + +joeMama.playGame(); +joeMama.loseMatch(); +console.log(joeMama); diff --git a/day_6/questions.md b/day_6/questions.md index cecd71563..528165971 100644 --- a/day_6/questions.md +++ b/day_6/questions.md @@ -1,13 +1,43 @@ ## Day 5 Questions 1. In your own words, what is a Class? +A class is a group of items that are are similar but not exactly the same object due to having different property values. 1. In relation to a Class, what is a property? +A property is a line of data that differentiates it from other objects. Also known as a key. 1. In relation to a Class, what is a method? +A method is a function that will make changes to the final key-value/value output of the specified key/property. 1. In the space below, create a Car class with at least 2 attributes and 2 methods +class Car { + constructor(make, model, speed){ + this.make = make; + this.model = model; + this.speed = speed; + this.speeding = false; +} + +goFast(){ + this.speed = "100mph"; +} +isSpeeding(){ + if (this.speed = "100"){ + this.speeding = true; + } +} +}; + +var audi_RS3 = new Car("Audi", "RS3", "45mph"); +console.log(audi_RS3); +audi_RS3.goFast(); +audi_RS3.isSpeeding(); +console.log(audi_RS3); + 1. What is the syntax to create an instance of a class? +var "instance"{ +} 1. What questions do you still have about classes in JavaScript? +What can you critique me on for my car class from above? How can I improve and simplify it? From ba18230a6007ed1965a53fd9801992a777e985a7 Mon Sep 17 00:00:00 2001 From: Josh Aragon Date: Tue, 8 Sep 2020 22:03:48 -0600 Subject: [PATCH 7/8] Add Frogs and Fizz Projects --- day_7/10_speckled_frogs.js | 12 ++++++++++++ day_7/fizzbuzz.js | 13 +++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 day_7/10_speckled_frogs.js create mode 100644 day_7/fizzbuzz.js diff --git a/day_7/10_speckled_frogs.js b/day_7/10_speckled_frogs.js new file mode 100644 index 000000000..f2669566e --- /dev/null +++ b/day_7/10_speckled_frogs.js @@ -0,0 +1,12 @@ + +var numberOfFrogs = 10 + +var numberWords = ['zero','one','two','three','four', +'five','six','seven','eight','nine', 'ten'] + +for (var i = numberOfFrogs; i > 0; --i) { + console.log(`${numberWords[i]} speckled frogs sat on a log + eating some most delicious bugs. + One jumped in the pool where its nice and cool, + then there were ${numberWords[i - 1]} speckled frogs.`) +} diff --git a/day_7/fizzbuzz.js b/day_7/fizzbuzz.js new file mode 100644 index 000000000..4a8acef90 --- /dev/null +++ b/day_7/fizzbuzz.js @@ -0,0 +1,13 @@ +/* For any number that is a multiple of 3, log 'Fizz' +* For any number that is a multiple of 5, log 'Buzz' +* For any number that is a multiple of both 3 and 5, log 'FizzBuzz' +* For all other numbers, log the number. +*/ + + +for (var i=1; i < 101; i++){ + if (i % 15 == 0) console.log("FizzBuzz"); + else if (i % 3 == 0) console.log("Fizz"); + else if (i % 5 == 0) console.log("Buzz"); + else console.log(i); +} From 0f05c83bf3ca6dede7372dff96548eacbee1df9c Mon Sep 17 00:00:00 2001 From: Josh Aragon Date: Tue, 8 Sep 2020 22:30:35 -0600 Subject: [PATCH 8/8] Add Caesar Cipher Solution --- day_7/caesar_cipher.js | 15 +++++++++++++++ day_7/high_level.md | 13 +++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 day_7/caesar_cipher.js create mode 100644 day_7/high_level.md diff --git a/day_7/caesar_cipher.js b/day_7/caesar_cipher.js new file mode 100644 index 000000000..dfef37b7d --- /dev/null +++ b/day_7/caesar_cipher.js @@ -0,0 +1,15 @@ +function CaesarCipher(str, num) { + + str = str.toLowerCase(); + + var result = ''; + var charcode = 0; + + for (var i = 0; i < str.length; i++) { + charcode = (str[i].charCodeAt()) + num; + result += String.fromCharCode(charcode); + } + return result; + +} +console.log(CaesarCipher('test', 2)); diff --git a/day_7/high_level.md b/day_7/high_level.md new file mode 100644 index 000000000..66a4b75d6 --- /dev/null +++ b/day_7/high_level.md @@ -0,0 +1,13 @@ +We can solve CaesarCipher by creating a function with the string we want to encode, followed by the number of letters we want to scramble by. (A+1 would be B/ A+3 would be D etc.) + +We then will use the charCodeAt method which returns the integer between 0 and 65535 representing the UTF 16 code unit at a given index. You add your num to the end of this method to scramble your word by this many letters. + +Next is the fromCharCode method which returns a string created from the sequence of UTF-16 code units. + +We then add the return result to the end of the function. + +Log the function with your wanted string and number of scrambles you want to add to your string phrase. + +https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode + +https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/charCodeAt