From 4b681bb29b819853be6dfb0ec46dbe4c99db71e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CAlexi?= <“alexi56”@comcast.net> Date: Tue, 4 Jun 2024 13:13:45 -0600 Subject: [PATCH 01/26] added weeks 0a and 0b --- .DS_Store | Bin 0 -> 8196 bytes 01-week/.DS_Store | Bin 0 -> 6148 bytes 0a-week/.DS_Store | Bin 0 -> 6148 bytes 0a-week/2-day/notes.md | 0 0a-week/2-day/scratch.js | 0 0a-week/3-day/notes.md | 0 0a-week/3-day/scratch.js | 0 0a-week/4-day/notes.md | 0 0a-week/4-day/scratch.js | 0 0a-week/5-day/notes.md | 0 0a-week/5-day/scratch.js | 0 0b-week/.DS_Store | Bin 0 -> 6148 bytes 0b-week/1-day/notes.md | 0 0b-week/1-day/scratch.js | 0 0b-week/2-day/notes.md | 0 0b-week/2-day/scratch.js | 0 0b-week/3-day/notes.md | 0 0b-week/3-day/scratch.js | 0 0b-week/4-day/notes.md | 0 0b-week/4-day/scratch.js | 0 0b-week/5-day/notes.md | 0 0b-week/5-day/scratch.js | 0 22 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 .DS_Store create mode 100644 01-week/.DS_Store create mode 100644 0a-week/.DS_Store create mode 100644 0a-week/2-day/notes.md create mode 100644 0a-week/2-day/scratch.js create mode 100644 0a-week/3-day/notes.md create mode 100644 0a-week/3-day/scratch.js create mode 100644 0a-week/4-day/notes.md create mode 100644 0a-week/4-day/scratch.js create mode 100644 0a-week/5-day/notes.md create mode 100644 0a-week/5-day/scratch.js create mode 100644 0b-week/.DS_Store create mode 100644 0b-week/1-day/notes.md create mode 100644 0b-week/1-day/scratch.js create mode 100644 0b-week/2-day/notes.md create mode 100644 0b-week/2-day/scratch.js create mode 100644 0b-week/3-day/notes.md create mode 100644 0b-week/3-day/scratch.js create mode 100644 0b-week/4-day/notes.md create mode 100644 0b-week/4-day/scratch.js create mode 100644 0b-week/5-day/notes.md create mode 100644 0b-week/5-day/scratch.js diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..32f5cfbba715f8acbd0de447283c3fc88e7df8a0 GIT binary patch literal 8196 zcmeHM&5ja55UyrXhM5*9tc1k^Hfsv?Q%#kO zIdczDp*=t!Kj+WF_$&xhY@>|HFmNEp{*) z4}*}|KZ9X77*EROUn;Ycy>>n4<-CITuKh8dwI|)lblmKY-q5#~aU2Gh$KBx7pg-#r zZ$FKrNp}$SM{F?Y^^x-S^&slSvt~SvdSkY2>kcpP_dsoj$n^{B(g~pn|&;@NfVphmDoH> zTayHPlUy<}Ez2cupi3rt!G|-5VF;h~`?t&WiyVL#36~Jc15^q>}%tTZu=KL#`NI0PiHlmZJ-X>l9mzE(%v^iY-PLg{w5h7NZMk zl46U|g*EwNX(C1!)+EW!!zrBL7%g~?xDOZ5TU`bey;RZyAMdu89WB6a0r5nB|G(`r zx%oQkU8{Yf{t|nqA literal 0 HcmV?d00001 diff --git a/01-week/.DS_Store b/01-week/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..207e0c0fd4020898d520b8469568978bee8371eb GIT binary patch literal 6148 zcmeHKyG{c!5Zr~F6p1D!4U&HVr10oX6bfp707A-0sVL~K=VSOjDwutMIL_B1gk~js z*6Uf@H`4hbBD#9oE=3k1GDk5~a~fvhX4gTIJD~a)&$qk%<7T(tG=}+`AzOPVOF5OT zJjnO;nDV4_K*0#twsPys41p#aWo zv-wdVYbrnmsKA#3wm%dU!G;%qr3u_pF`=z(dZ0wY!PiJ_5> zcu8JO>;ofRG#?+DGk-o_)Mv-|#p$9okTn&c0z(B3qq(s2{|3KI^N~MHVT%e-fq$le z&enJ96+SA@*3swLSzA!EM47H(^Ds}0|7>Svoe9ci+gqZmQP&!uX#K3lcp+AP-SKhM?;<((35V9rb zImvVG?n#%#BBHC;?NVeRA~QHq88nQ;&8d?hPl0M{yglspFPq(d(^%$j4)NWmvXl$i z%Cmfbe@b!>zdeQ-^KyjwK44z8nR-58UXL&j1Ln;L^Z0{_Zdxjk3Zw$5Kq@ez0M2aM zZ0?wCDv%1K0$&Pne<*Nb4eT6k>p){A0C0j~GsL_&Gp7XBz|IjfF!fZRr)rcK>ggCS z!K;Ctqo<2T@uBhL&*DYx=~%xQU9>u8n+l`?eFaXvyWshMhhL^yEM47H(^Ds}0|7>Svoe9ci+gqZmQP&!uX#K3lcp+AP-SKhM?;<((35V9rb zImvVG?n#%#BBHC;?NVeRA~QHq88nQ;&8d?hPl0M{yglspFPq(d(^%$j4)NWmvXl$i z%Cmfbe@b!>zdeQ-^KyjwK44z8nR-58UXL&j1Ln;L^Z0{_Zdxjk3Zw$5Kq@ez0M2aM zZ0?wCDv%1K0$&Pne<*Nb4eT6k>p){A0C0j~GsL_&Gp7XBz|IjfF!fZRr)rcK>ggCS z!K;Ctqo<2T@uBhL&*DYx=~%xQU9>u8n+l`?eFaXvyWshMhhL^y Date: Tue, 4 Jun 2024 20:43:22 -0600 Subject: [PATCH 02/26] week 1 day 2 --- 0a-week/2-day/scratch.js | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/0a-week/2-day/scratch.js b/0a-week/2-day/scratch.js index e69de29..0d7df18 100644 --- a/0a-week/2-day/scratch.js +++ b/0a-week/2-day/scratch.js @@ -0,0 +1,25 @@ +// Single Line Comment - This line will be ignored by the computer + +/* Multi-Line Comment + +Hey +Ignored +Also Ignored +*/ + +//This code does this: + +//These are console log statements +//They print out data to the terminal/commandline/console + +//The console log statements are printing a data type called a string +// Strings in JS use "" or '' +console.log("Howdy!"); +console.log("Hi what's up I'm bob how are you"); +console.log("eep"); + +//Syntax: +//The keywords, characters or symbols that we use to write code +//in specific language +//Most programming languages follow all of the same principles +//and fundamental ideas, they just have different syntax From 0a092e98fd287089a29a08057f003de93f8513ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CAlexi?= <“alexi56”@comcast.net> Date: Wed, 5 Jun 2024 17:55:42 -0600 Subject: [PATCH 03/26] Week 1 Day 3 --- 0a-week/3-day/scratch.js | 162 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 162 insertions(+) diff --git a/0a-week/3-day/scratch.js b/0a-week/3-day/scratch.js index e69de29..7c56c61 100644 --- a/0a-week/3-day/scratch.js +++ b/0a-week/3-day/scratch.js @@ -0,0 +1,162 @@ +//Basic data types of Javascript + +//Numbers: 1, 2454365, 234.5, -234 + +//Strings: "Hey!!!", '34566@$%@Howdy', `GreetingS!!` + +//Booleans: true false + +//We gave it a value, it has a value of nothing +//Null: null + +//That something was never given a value +//Undefined: undefined + +//Lists of comma seperated items wrapped in square brackets +//You can put any data types in an array +//Arrays: [1, 2, 4, true, false, "Hey!", [], {}] + +//Collection of related data using key value pairs in curly brackets +//Objects: { key: value } +//{ name: "King", age: 12} + +//Variables - A box, with a name, in which we store data +//To create a variable we begin with the keyword let +//Then we name the variable +//Then we assign it a value using an = +//JS doesn't care about the variables name, it just uses it to find what is +// inside of the variable + +let catsName = "King"; + +//console.log(catsName); + +//Declaring vs. initializing + +//Created an empty variable +let fruit; + +//This will console log undefined as we never assigned it a value +//console.log(fruit); + +//Declaring a variable is the let varName part + +//Initialization is when we declare a variable and assign it a value on the same line + +//Assignment is when we use the equal sign to give something a value + + +//Reassignment + +let cat = "King"; + +//console.log(cat); + + +//We do not use let +//We are reassigning the value to uppercase + +cat = "KING"; + +//console.log(cat) + +//camelCase is the naming convention that JS uses + +let numberVar = 12345; + +let stringVar = "Anything"; + +let boolVar = true; + +let nullVar = null; + +let undefinedVar; + +//Reassigning the variables +boolVar = false; + +numberVar = "NUMBER" + +//Comparison operators - how we compare stuff +//They spit out a true or a false + +// >, <, >=, <= , == === + +//console.log(8 <= 9); + +//Double equals (Loose equality) == +//Do the values equal eachother, doesn't care about data type +//console.log(5 == 5); +//console.log('5' == 5); + +//Triple equals (Strict equality) === +//Javascript is pretty smart +// The values and the data types equal eachother + +//console.log('5' === 5); +//These will not equal eachother + +//Arithmetic operators +// +, -, *, / +// % Modulo +//Modulo - Divides two numbers and gives you the remainder + +//console.log(17 % 5) + +//Logical Operators - Allow us to chain comparison operators together +// ! (not, bang) && (and) || (or) + +// ! - Will flip a value to the opposite value +//You put the ! in front of the value + +//console.log(!false) + +//&& - Requires both expressions to be true, for it to return true + +//console.log(5 > 3 && 5 > 2) //true + +//console.log(5 > 3 && 5 > 10) //false + +// || - Only requires one to be true +// only returns false if both are false + +//console.log(5 > 3 || 5 > 2) //true + +//console.log(5 > 3 || 5 > 10) //true + +//console.log(5 < 3 || 5 > 10) // false + +//String data type: + +//let string = "Hello World!"; + +//Concatenation - Smushing two strings together +//You can do it with two or more strings or variables that contain strings +//We concatenate with the + + +//JS will smush them together exactly as they are +//console.log("Hello" + ' ' + "World"); + +//Concat with variables +//console.log("My cat says " + string); + +//console.log("Hey" + userName + "we miss you!"); + +//Javascript stores the length of every string in a length property + +let string = "Hello World!"; + +console.log(string.length); //12 + +//To access an individual letter in a JS string +//we can use something called indexing +//WE ALWAYS USE SQUARE BRACKETS WHEN INDEXING +//Indexes start at 0 + +console.log(string[4]); // o + +console.log("Hey"[2]); //y + +console.log(string.indexOf('W')) //6 +console.log(string.indexOf('w')) //Returns -1 because it can't find lowercase w +console.log(string.indexOf('o')) From bbcbe37aa27af27a14cfa5907f47444ff918ff6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CAlexi?= <“alexi56”@comcast.net> Date: Wed, 5 Jun 2024 23:12:19 -0600 Subject: [PATCH 04/26] add resources --- .DS_Store | Bin 8196 -> 8196 bytes additional-resources/cloning.md | 76 ++++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+) create mode 100644 additional-resources/cloning.md diff --git a/.DS_Store b/.DS_Store index 32f5cfbba715f8acbd0de447283c3fc88e7df8a0..72985c5b8c4dc6023e259acf1eba02b7a637b9f4 100644 GIT binary patch delta 76 zcmZp1XmOa}&nUeyU^hRb^kyD`oy?QjMCC-+FfcF}{s#jfi-Cci!GIxY@>QX0j7gK% b2up4@5xvYbvB76EyTmt^&7PwBfE-T%+j1I; delta 206 zcmZp1XmOa}&nUAoU^hRb%w`^eoy>te3E45>hv&7i=L%#hDez)ge2Gm6P<<`mt; Tw3%Jv8_VQ9!s>X{t!DxNiD);O diff --git a/additional-resources/cloning.md b/additional-resources/cloning.md new file mode 100644 index 0000000..42ad327 --- /dev/null +++ b/additional-resources/cloning.md @@ -0,0 +1,76 @@ +# Cloning-A-Repo +- In this md file, we will cover how to Clone, change, and then share a repo between yourself and your partner for pair programming purposed. +- We will be using your very first POJO proctice in these examples, if you need ot clone another repo, then follow these steps on that repo instead. + +## Steps for Cloning +- 1.) Go to the repositories address on github, in this case, we will be using +- [https://github.com/appacademy/practice-for-week-02-pojo_basics](https://github.com/appacademy/practice-for-week-02-pojo_basics) +- 2.) Click on the green code button. + +![Alt text](Screenshot%202023-08-09%20134548.png) + +- 3.) Verify you are using the auth that you have setup, default is typically HTTPS so leaving this option highlited is fine, if you have changed to ssh, then click this option instead. + +![Alt text](Screenshot%202023-08-09%20134748.png) + +- 4.) Click the copy button next to the url in the bottom right + +- 5.) Open up your terminal, navigate to where you would like to store this repo locally and type in git clone, then paste what you just copied from github +``` +//example for this specific repo we are cloning +git clone https://github.com/appacademy/practice-for-week-02-pojo_basics.git +``` +- 6.) Remove the connection between your computer and this git repo in order to create your own. + - cd into this repo + - in your terminal type in +``` +rm -rf .git +``` +- 7.) NPM install and add .gitignore + - run these command in the root of this dir to in node packages and create .gitignore +``` +npm install +touch .gitignore +``` +- open your .gitignore and add your /node_modules on line 1 +``` +/node_modules +``` +- 8.) Initialize your new local git repo, add all files in repo to staging, then commit + - run these commands +``` +git init +git add . +git commit -m 'first commit' +``` +- 9.) Create a Github Repo to connect your local git repo to. + - Make sure you are signed into github + - navigate to this url + - [https://github.com/new](https://github.com/new) +![Alt text](Screenshot%202023-08-09%20140113.png) +- 10.) Finish Creating repo + - Choose yourself as an owner + - Give your repo a name + - Click Create repository in the bottom right of screenshot! +- 11.) Copy the commands in the second option of the below screenshot +![Alt text](Screenshot%202023-08-09%20140515.png) + + - Navigate back to your terminal and past these commands + - If you receive an error when pasting the commands all at once, please attempt pasting them one at a time + - After you have pasted to last command and it has finished running, navigate back to your broswer, refresh your github page, and verify the correct things were added to this repo + +- 12.) If you are sharing this newly created repo with a a partner, please follow the md in the Sharing directory + - If not, every time you are done with a problem, or maybe hit a checkpoint such as being finished for the day, make sure to add, commit and push, and your partner pulls. + - you can do this by running these below commands +``` +# you + +git add . +git commit -m 'add your descriptive commit message of what you did' +git push +``` +``` +# partner + +git pull +``` \ No newline at end of file From 7018ff2a9cafb818188143ce9f1a7c3bad02ffce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CAlexi?= <“alexi56”@comcast.net> Date: Sat, 8 Jun 2024 12:38:44 -0600 Subject: [PATCH 05/26] week 0a day 5 --- 0a-week/5-day/scratch.js | 232 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 232 insertions(+) diff --git a/0a-week/5-day/scratch.js b/0a-week/5-day/scratch.js index e69de29..afd3a95 100644 --- a/0a-week/5-day/scratch.js +++ b/0a-week/5-day/scratch.js @@ -0,0 +1,232 @@ +//Functions - Are reusable blocks of code +// camelCaseCaseCase +/* + +function funcName() { + CODE THAT THE FUNCTION WILL RUN +} + +*/ +//In order for the function to run the code inside of it +//We must "call"/"invoke" it +//To call a function, AFTER IT HAS BEEN CREATED, you simply use the function name() + +function sayHello() { + console.log("Hello!"); +} + +// sayHello(); +// sayHello(); +// sayHello(); +// sayHello(); +// sayHello(); +// sayHello(); +// sayHello(); +// sayHello(); + +//The parenthesis store variables for the function that we call parameters + +//Says hi to someone + +//This right here is a function declaration +function sayHiTo(name, otherName) { // let name; + //the name and othername parameters will only exist inside of the curly braces + console.log(`Hello ${name} welcome back. Is your bestfriend ${otherName}?`) + // console.log('Hello ' + name + ', welcome back') + // console.log('Hello ${name}') +} + +//The values that we pass into the function call are arguments +// sayHiTo("King", "Onyx"); + +// sayHiTo("Greg", "Mary"); + +// sayHiTo("Pickles", "DoobleBob") + +// function dataTypes(number) { +// console.log(number * 9); +// } + +// dataTypes(9) +// dataTypes("DoodleBob") + +// function dataTypes(number, string, array, bool) { +// console.log(number, string, array, bool) +// } + +// dataTypes(8, "King", [1, 2, 3], true) + +// function yellSomething(yell) { +// console.log(yell.toUpperCase() + '!!!'); +// } + +// yellSomething("What are you doing?"); + +// function sayHello(name) { +// console.log(`Hi ${name}`) +// } + +// console.log(name) + +// sayHello("King") + +//RETURN STATEMENTS +//Spit stuff out of the function so we can use it anywhere in the program +//What if I want to save the result OUTSIDE of the function + +function doesMath(num1, num2) { + console.log(num1 * num2) //SPIT THE RESULT OF THIS EXPRESSION OUT OF THE FUNCTION + + return "DoodleBob" +} +//How can we grab what a function spits out? + +//THE FUNCTION CALL EVALUATES TO THE RETURN STATEMENT + +//console.log(doesMath(9, 9)) + + + +//If we don't specify what the function is going to return, it will return undefined +//EVERY SINGLE FUNCTION IN JS has a return statement, but it is undefined unless otherwise specified + +//But not only does the return spit stuff out, but also lets JS know that the function can end + +//console.log(`The result of the math equation is: `) + + +//Return yelled name + +function yellName(name) { + let yelledName = name.toUpperCase(); + + return yelledName +} + +let kingUpperCase = yellName("King"); + +//console.log(kingUpperCase); + +/* +write a function that takes in two parameters which would be two separate words +and it would flip the first letter of each word. +For example, if you put in 'monkey' and 'business' it would return bonkey musiness +*/ + +function flipFirstLetters(word1, word2) { + //Get the first letter of each word + let word1letter = word1[0] //First letter of word one + let word2letter = word2[0] //First letter of word two + + let endOfWord1 = word1.slice(1, 6); //Create a NEW string from a specified portion of another string + let endOfWord2 = word2.slice(1); + + console.log(word2letter + endOfWord1, word1letter + endOfWord2) + //console.log("ORIGINALS", word1, word2) +} +// flipFirstLetters("monkey", "business"); + +// flipFirstLetters("Food", "Google"); + +// flipFirstLetters("Cheese", "Toastie"); + +//In javascript strings cannot be changed + +//Shorter version of that ^^ +function flipFirstLetter(word1, word2) { + + console.log(word2[0] + (word1.slice(1)), word1[0] + (word2.slice(1))) + +} + +//flipFirstLetter("monkey", "business") + + +//CONDITIONALS +//Control flow is the order in which instructions are executed +//Ex: if this, do this. If that, do that + +//Two control structures which allow us to modify the flow of a program +// 1. Conditionals +// 2. Loops + +//Conditionals +// - IF statements, ELSE IF statements, ELSE statements + +/* +SYNTAX: + +if (condition to be true) { + CODE TO BE EXECUTED +} else if (another condition) { + CODE TO BE EXECUTED +} else { + CODE TO RUN IF NONE OF THE ABOVE CONDITIONS ARE TRUE +} + +YOU DONT NEED TO CHAIN THEM, BUT YOU CAN IF YOU WANT TO + +YOU CAN ONLY HAVE: 1 if statement and 1 else statement +BUT you can have as many else if statements as you want +*/ + +let color = "blue"; + +// if (color === 'pink' || color === 'Pink') { +// console.log("Yay pink!"); //Will only run if the condition is true +// } else if (color == 'blue') { +// console.log("OMG blue"); +// } else if (color === "yellow") { +// console.log("yellow.") +// } else { +// console.log(`You chose: ${color}`); +// } + +//IF ONE OF THESE CONDITIONS IS TRUE, js will run its code and it won't evaluate +//ANYTHING else +//These conditions are CHAINED together + + +//THE IF statement creates a block or a chain of conditionals +//THESE are two seperate blocks +//They will both run if the color is blue +// if (color === 'blue') { +// console.log('blue') +// } + +// if (color[color.length - 1] === 'e') { +// console.log("Ends in e") +// } + +//THIS ONE is chained and so only one will run if the color is blue +// if (color === 'blue') { +// console.log('blue') +// } else if (color[color.length - 1] === 'e') { +// console.log("Ends in e") +// } else { +// console.log("Dude what color are you talking about") +// } + + +//Write a function that takes in two params +//The first is a name and the second is whisper or yell +//Based on the second parameter console log the name whispered or yelled + +function whisperOrYell(name, speakingVoice) { + if (speakingVoice === 'whisper') { + console.log(name.toLowerCase()); + } else if (speakingVoice === 'yell') { + console.log(name.toUpperCase()); + } else { + console.log("BOO"); + } +} + +whisperOrYell('Greg', 'whisper'); + +whisperOrYell('Robert', 'yell'); + +whisperOrYell('Mike Jones', 'yell'); + +whisperOrYell('goobles', 'mary'); + From 3b8675d95420933151944c0899d90c957795e0ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CAlexi?= <“alexi56”@comcast.net> Date: Sat, 8 Jun 2024 12:39:20 -0600 Subject: [PATCH 06/26] weeks --- 0a-week/.DS_Store | Bin 6148 -> 6148 bytes 0a-week/3-day/scratch.js | 2 +- 0a-week/4-day/scratch.js | 190 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 191 insertions(+), 1 deletion(-) diff --git a/0a-week/.DS_Store b/0a-week/.DS_Store index dde69856cf0d92eb7def888da38d868376eccce8..b129259d921f74389553419315e58d75eb775606 100644 GIT binary patch delta 36 scmZoMXfc@J&&V<{U^hDp0|NsqgVE#(jAEOE7`L)bY|z@w&heKY0JLZdF8}}l delta 48 xcmZoMXfc@J&&WD4U^hD}0|NsqgW==}jADEY?m&*&e<;|@!+4QxGdss$egI^)5l#RA diff --git a/0a-week/3-day/scratch.js b/0a-week/3-day/scratch.js index 7c56c61..fd5b693 100644 --- a/0a-week/3-day/scratch.js +++ b/0a-week/3-day/scratch.js @@ -80,7 +80,7 @@ numberVar = "NUMBER" //Comparison operators - how we compare stuff //They spit out a true or a false -// >, <, >=, <= , == === +// >, <, >=, <= , == === != !== //console.log(8 <= 9); diff --git a/0a-week/4-day/scratch.js b/0a-week/4-day/scratch.js index e69de29..048987c 100644 --- a/0a-week/4-day/scratch.js +++ b/0a-week/4-day/scratch.js @@ -0,0 +1,190 @@ +//Truthy and Falsey value +//Certain expressions in JS are inherently truthful or false + +4 > 3 //True +3 > 4 //False + +//Indexing strings + +let str = "King"; + +//When using .indexOf we give it a character to receive an index +// Ex: str.indexOf('K') // 0 + +//When using indexing str[0] we give it an index and it returns a character + +//str[0] //K + +//"King"[0] //K + +//Indexing starts at 0 + +//Getting the last character of a string that we don't know the size of + +//We can use the length of the string - 1 + +//console.log(str.length); //The length is 4 + +//console.log(str[str.length - 1]) // g str.length - 1 will give us 3 + +//Interpolation vs Concatenation + +//Concatenation - uses the + +//console.log("Hello " + "World"); +// console.log(str + " says hello"); + +//Interpolation - Uses `` (backticks) and ${} to put variables into strings +//${} only works if it is inside of backticks +// console.log(`${str} says hello`); +// console.log('${str}'); + +// console.log(`${4 + 4} number`); + +let nameVar = "Onyx"; +let age = 13 + +// console.log(`${nameVar} is so cute and he happens to be ${age}.`); + +//Numbers + +let i = 4; +i + 3; //Do not reassign the value of i + +// console.log(i + 3, i); //7 4 + +//Long hand +i = i + 3; //Reassign it to i + 3 + +//shorthand +i += 3; //Reassign it to i + 3 + +// console.log("AFter reassignment: " + i) // 7 + +//Increment and Decrement operators + +//Long hand +i += 1; + +i++; //Add one to a number DOES REASSIGN it + +//long hand +i -= 1; + +i--; + +//Examples + +let num = 4; + +num--; +num + 45; //This evaluates to 48, but JS doesn't store that in num + +//console.log(num); + +let num5 = 14; + +// console.log(num5) // 14 + +let expression5 = num5++; //Will set expression5 to 14 +num5++ +// let expression5 = 5 += 1; //Its sets it to 15 + +// console.log(num5); + +let predictExpression5 = 14; + +// console.log(expression5); + +// i++ Returns the value BEFORE incrementing +// ++i return the value AFTER incrementing +// i+= 1 returns the value AFTER incrementing +//Alex promptly quits her job. + +// console.log(num5 == num5++); + +// DeMorgans Law +//How you evaluate boolean expressions + +/* +If the ! is outside of parenthesis then you apply the ! to each expression + and you flip the logical operator + + +A === True + +B === False + + +!(A || B) -> False + +!(!A && !B) -> True + +!(A || !B) -> False + +*/ + +// != / == loosely does not equal !== strictly + +// console.log('5' != 5); //Would be false because THEY DO loosely equal + +// console.log('5' !== 5); //True bc they don't strictly equal + +//When we use logical operators to chain expressions +// + +//console.log(5 > 4 || 5 > 6); + +//If JS sees that the first expression is true and that there is an OR +// IT WILL NOT check the second expression + +//FUNCTIONS - A function in JS is a reusable block of code +// Stores a block of code, until we "Call" it and then it executes that code + +//To create a JS function, start with the keyword function +//Then name it +/* +JS Function syntax: + +function funcName() { + //Code to execute +} + +*/ + +//Let's write a function to say hello! + +function sayHello() { + console.log("Hello!"); + console.log("I'm greg"); +} +//In order to get this to run we "call" or "invoke" +//To call a function use its name and then parenthesis + +// sayHello(); //This line runs the code inside of the function + +//Parameters vs Arguments +//Parameters are just variables that go into a function +//Function declaration is the act of creating a function +//The variables in the function declaration are PARAMETERS + +function sum(x, y) { // let x; let y; + console.log(x + y) +} +//How will I actually give those variables values? +//We will call the function and PASS in ARGUMENTS + +//The values that we pass in for the parameters are called arguments +// sum(5, 7); +// sum(6, 8); +// console.log(5 + 4); +// console.log(45 + 6); + +//Javascript doesn't care if you pass in too many arguments +//Javascript simply ignores the extra args +function hello(name) { //let name; + console.log("Hi " + name); +} + +//hello("King", "Onyx") Providing extra + +hello(); //Hi undefined \ No newline at end of file From 92a60967ef44a81523735af6ff4720c6d76c85ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CAlexi?= <“alexi56”@comcast.net> Date: Sat, 8 Jun 2024 12:48:12 -0600 Subject: [PATCH 07/26] greg --- 0a-week/5-day/scratch.js | 1 + 1 file changed, 1 insertion(+) diff --git a/0a-week/5-day/scratch.js b/0a-week/5-day/scratch.js index afd3a95..f86e2b0 100644 --- a/0a-week/5-day/scratch.js +++ b/0a-week/5-day/scratch.js @@ -230,3 +230,4 @@ whisperOrYell('Mike Jones', 'yell'); whisperOrYell('goobles', 'mary'); +console.log('greg') \ No newline at end of file From 72da18382f3c305b8ba4d762d1b80aa4710e5cea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CAlexi?= <“alexi56”@comcast.net> Date: Mon, 10 Jun 2024 16:55:54 -0600 Subject: [PATCH 08/26] week 2 day 1 --- 0b-week/1-day/scratch.js | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/0b-week/1-day/scratch.js b/0b-week/1-day/scratch.js index e69de29..6b6c9b8 100644 --- a/0b-week/1-day/scratch.js +++ b/0b-week/1-day/scratch.js @@ -0,0 +1,30 @@ +//Returns help us spit stuff out of functions and tells the function that it is done +//Every function has a return + +function sayHi(name) { + console.log(`Whats up ${name}`); + + //Implicit return + //If we don't use the keyword return, JS will return anyway + //It will return undefined +} + +//sayHi("King"); + +//console.log("After function") + + +function multiply(num1, num2) { + // return num1 * num2; + console.log('hi') + console.log(num1 * num2) + return "Howdy" +} + +//THE FUNCTION CALL EVALUATES TO THE RETURN STATEMENT + +let result1 = multiply(9, 9); //I am setting result equal to whatever the function returns +let result2 = multiply(3, 3); + +//String interpolation +console.log(`The result of this function is: ${result2}, ${result1}`); \ No newline at end of file From 92a3a5a994af9ae0e04cb3b79977a38a99e91a1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CAlexi?= <“alexi56”@comcast.net> Date: Tue, 11 Jun 2024 19:38:03 -0600 Subject: [PATCH 09/26] week 2 day 2 --- 0b-week/2-day/scratch.js | 92 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) diff --git a/0b-week/2-day/scratch.js b/0b-week/2-day/scratch.js index e69de29..f57dcf1 100644 --- a/0b-week/2-day/scratch.js +++ b/0b-week/2-day/scratch.js @@ -0,0 +1,92 @@ +//Control flow - We can control in what directions the program goes +//Two control flow structures: conditionals and loops + +//Two kinds of loops - FOR and WHILE + + +//WHILE LOOPS - Will execute code for as long as a condition remains true + +/* + +SYNTAX - + +while (condition) { + CODE TO EXECUTE WHILE CONDITION IS TRUE + + //Some piece of code that will push it towards ending the loop + //If we don't have end loop expression we will create an infinite loop +} +*/ +//If you ever need to stop an infinite loop you can run ctrl c + +// while (true) { +// console.log('King') +// //This will be infinite +// } +//Generally there is a variable outside of the loop that controls the condition +//Every "loop" is an iteration +//WHY USE A WHILE OVER A FOR - You need to access your initial expression outside of the loop +//Generally with a while WE DONT KNOW THE AMOUNT OF ITERATIONS that will occur +// let i = 0; + +// while (i < 5) { +// console.log(i); +// i++; //Loop end expression +// } + +// console.log("After looping: ", i) + +//FOR LOOPS +//Have 3 sections seperated by SEMICOLONS + +/* +initial expression - A variable that we increment or again just push towards an ending condition +// Init expression is run ONE TIME before the loop starts and NEVER AGAIN + +condition - must be true to keep looping +CHECKED ON EVERY ITERATION + +end loop expression - does something to get the initial expression to make the condition false +EXECUTED AFTER THE BLOCK OF CODE INSIDE THE CURLY BRACES + +for (initial expression; condition; end loop expression) { + CODE TO REPEAT +} + +*/ + + +// for (let i = 0; i < 5; i++) { +// console.log(i) +// } +//console.log("After looping: ", i) This will throw an error + + +/* +Loop through a string and console log each letter +*/ +let cat = "King"; + +for (let pickles = 0; pickles < cat.length; pickles++) { + console.log(cat[pickles]) +} + +//console.log(cat[0]) //Indexing + + +// Loop through a string and console log each letter capitalized + +let cat2 = "King"; + +for (let pickles = 0; pickles < cat2.length; pickles++) { + console.log(cat2[pickles].toUpperCase()) +} + + +/* +Define a function hasVowel that takes in a string parameter. The function should +return a boolean, true if the string contains at least one vowel, false +otherwise. + +Vowels are the letters "a", "e", "i", "o", "u". +*/ \ No newline at end of file From 382cb16a0a9938d1d82e792a4cc101a7c7d5f37c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CAlexi?= <“alexi56”@comcast.net> Date: Wed, 12 Jun 2024 19:06:08 -0600 Subject: [PATCH 10/26] week 0b day 3 --- 0b-week/3-day/scratch.js | 146 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 146 insertions(+) diff --git a/0b-week/3-day/scratch.js b/0b-week/3-day/scratch.js index e69de29..8620020 100644 --- a/0b-week/3-day/scratch.js +++ b/0b-week/3-day/scratch.js @@ -0,0 +1,146 @@ +//While and for loops + +/* +WHILE LOOP SYNTAX - + +while loops will keep running as long as their condition is true +we want to structure our code so that at some point the codition becomes false +^^doing this will prevent infinite loops + +Typically we have an outside variable that the condition is reliant upon +so the at of changing the value of that variable should at some point +make the condition false + +while (condition) { + Code to repeat +} +*/ + +// let i = 0; + +// while (i < 10) { +// console.log(i); +// i += 2; +// } +/* +FOR LOOP SYNTAX +inside the parenthesis we have three semi colon separated sections + +initial expression - variable that the condition is reliant upon. Its run ONE TIME +before the loop begins + +condition - Is checked every iteration, and the +loop will only continue as long as its true + +loop end expression - Some expression that gets our initial expression closer + to making the condition false + +for (initial expression; condition; loop end expression) { + code to repeat +} +*/ + +// for (let i = 300; i >= 0; i -= 25) { +// console.log(i) +// } + +let string = "barnacle" + +// for (let i = 0; i < string.length; i += 1) { +// console.log(string[i]); +// } + +/* +Define a function logBetweenStepper that takes in 3 numbers as parameters. The +function should print out numbers between a minimum number and a maximum number +at defined intervals. The first parameter should represent the minimum number. +The second parameter should represent the maximum number. The third parameter +should represent the interval. +*/ + +// function logBetweenStepper(min, max, interval) { +// for (let i = min; i <= max; i += interval) { +// console.log(i); +// } +// } + +//logBetweenStepper(5, 3000, 150); +//logBetweenStepper(0, 20, 2) + + +//ARRAYS - Another basic data type +// Arrays are just lists of items that can be any data type +// collections +//ARRAYS ALSO HAVE INDICES just like strings +/* + +[all of your data goes in here comma separated] + +[1, 2, 3] + +["Hi", "howdy", "hello"] + +[true, false, true] + +[1, 2, true, "Howdy", false] +*/ + +//let fruit = ["apple", "orange", "lemon", "pear"]; + +//Indexing +//console.log(fruit); //the whole thing +//console.log(fruit[2]); +// let orange = fruit[1]; +// console.log(orange) + +//Arrays have a length property + +//console.log(fruit.length); + +// fruit[1] = "strawbies"; + +// console.log(fruit); + +// fruit[3] = false; + +//console.log(fruit); + +//You can also concatenate them + +let veggies1 = ["brocc", "lettuce", "tomato"]; + +let veggies2 = ["greenbeans", "turnip", "spinach"]; + +let allVeggies = veggies1.concat(veggies2); // [giant array] + +//console.log(allVeggies) + +//Index of takes in an item and returns the index that it is in + +//console.log(veggies1.indexOf('lettuce')) + +//.index() is a function which is why we call() it + +//fruit[1] //indexing using square brackies + +let fruit23 = ["apple", "orange", "lemon", "pear", "cherries", "peach", "guava"]; + +//console.log(fruit23[fruit23.length - 1]) + +//Loop through the fruit23 array and console log each fruit + +// for (let i = 0; i < fruit23.length; i++) { +// console.log(fruit23[i]) +// }å + +//Loop backwards by one through an array + +// for (let i = fruit23.length - 1; i >= 0; i--) { +// console.log(fruit23[i]) +// } + +// //Loop backwards by two through an array +// for (let i = fruit23.length - 1; i >= 0; i -= 2) { +// console.log(fruit23[i]) +// } + From 8dbfccfdfb6d0f5a4cff04eaedee23901420d375 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CAlexi?= <“alexi56”@comcast.net> Date: Mon, 17 Jun 2024 17:51:10 -0600 Subject: [PATCH 11/26] week 1 day1 for real --- 01-week/1-day/scratch.js | 189 +++++++++++++++++++++++++++++++++++++++ 0b-week/3-day/scratch.js | 4 +- 2 files changed, 191 insertions(+), 2 deletions(-) diff --git a/01-week/1-day/scratch.js b/01-week/1-day/scratch.js index e69de29..c7bce09 100644 --- a/01-week/1-day/scratch.js +++ b/01-week/1-day/scratch.js @@ -0,0 +1,189 @@ +//Conditionals + +// if (true) { +// console.log("Hello") +// } + +//Else if and else can only be chained onto an if statement + +// if (true) { + +// } else { + +// } + +//FUNction +//Reusable blocks of code +//You can put any valid code into them including conditionals, loops + +// function sayHi() { +// console.log("Hello") +// } + +//To actually use the code inside of the function we have to call it + +//sayHi(); //This triggers the code to run + +//Parameters vs arguments + +// function sayHelloTo(name) { +// console.log(`Hi, ${name}`); +// } + +// sayHelloTo("King"); +// sayHelloTo("Brett"); + +// function condish(name) { +// //We can put conditionals into functions +// if (name === "Marlon") { +// console.log("Yay!! Marlon"); +// } else if (name === "Andres") { +// console.log("Yay!! Andres"); +// } else { +// console.log("Who are you: ", name) +// } +// } + +// condish("Marlon"); +// condish("Alex"); + +//Mutable vs Immutable stuff + +//Some things in javascript can change, others cant + +//Things that can change: (mutable data types) +// -Arrays +// -Objects + +//Things that cant change: (immutable data types) +// - Numbers +// - Strings +// - Booleans + +//Since variables are just boxes that hold stuff, we can tell a variable to hold a NEW string + +// let string = "King"; + +// let upperString = string.toUpperCase(); + +// string = string.toUpperCase(); + +// console.log(upperString, string); + +//Arrays are mutable so we can change them + +let fruit = ["Apple", "Orange", "Peach", "Guava"]; + +//console.log(fruit); + +fruit[1] = "Lemon"; + +//console.log(fruit); + +//IMMUTABILITY EXAMPLE - +// let string = "Barnacle" +// string[1] = 'L' + +// console.log(string) + +//console.log(["Apple", "Orange", "Peach", "Guava"][1]) + +//Nested array - Arrays within arrays +let arr = [true, false, [1, 2, 3]] + +//console.log(arr[2]) // [1, 2, 3] + +//console.log([1, 2, 3][1]) + +//console.log(arr[2][1]) //Return 2 + +let nestedFruit = ["Apple", "Peach", "Guava", ["Lemon", "Lime", "Orange"], "cherries", "Watermelon"]; + +//console.log(nestedFruit[3][1]) //Lime + +// console.log(nestedFruit[0]) +// console.log(nestedFruit[3][0]) + +//console.log(nestedFruit[0] + nestedFruit[1]) + +nestedFruit[0] = true + +//console.log(nestedFruit); + +let citrusFruits = nestedFruit[3]; + +//console.log(citrusFruits) // ["Lemon", "Lime", "Orange"] + +//console.log(citrusFruits[0]) // "Lemon" + +//let animals = ["Lion", "Otter", ["Bobcat", "Housecat", ["Tabby", "Orange", "Hemmingway", "russian blue"], "Cougar"], "Penguin"] + +//console.log(animals[2][2][3]) //Russian blue + + +//Loops + +let fruits = ["Apple", "Orange", "Peach", "Guava"]; +let veggies = ["Brocc", "lettuce", "Tomato", "cucumber"] + +//INSTEAD OF THIS +// console.log(fruits[0]); +// console.log(fruits[1]); +// console.log(fruits[2]); +// console.log(fruits[3]); + +// for (let i = 0; i < fruits.length; i++) { +// console.log(fruits[i]) +// } + +// function printsEverythingInArray(arr) { +// for (let i = 0; i < arr.length; i++) { +// console.log(arr[i]) +// } +// } + +// printsEverythingInArray(veggies) + +let nums = [1, 2, 3, 4, 5, 6, 7, 8, 9] + +function addNumsFromArray(arrOfNums) { + let sum = 0; + for (let i = 0; i < arrOfNums.length; i++) { + sum += arrOfNums[i] + } + + return sum; +} + +console.log(addNumsFromArray(nums)) + +/* + +Every time we call a function it starts from scratch + +Every time we loop, the loop "starts from scratch" + +*/ + +// let sum = 0 +// function randoFunc(num) { +// return sum += num; +// } + +// console.log(randoFunc(5)) +// console.log(randoFunc(5)) +// console.log(randoFunc(5)) + + +//RETURN STATEMENTS ARE ONLY FOR FUNCTIONS + +function spitOutName(name, whisperOrYell) { + if (whisperOrYell === 'whisper') { + return name.toLowerCase() + } else if (whisperOrYell === 'yell') { + return name.toUpperCase() + } + +} + +console.log(spitOutName("King", 'yell')) \ No newline at end of file diff --git a/0b-week/3-day/scratch.js b/0b-week/3-day/scratch.js index 8620020..801cbf8 100644 --- a/0b-week/3-day/scratch.js +++ b/0b-week/3-day/scratch.js @@ -26,7 +26,7 @@ while (condition) { FOR LOOP SYNTAX inside the parenthesis we have three semi colon separated sections -initial expression - variable that the condition is reliant upon. Its run ONE TIME +initial expression - generally variable that the condition is reliant upon. Its run ONE TIME before the loop begins condition - Is checked every iteration, and the @@ -44,7 +44,7 @@ for (initial expression; condition; loop end expression) { // console.log(i) // } -let string = "barnacle" +// let string = "barnacle" // for (let i = 0; i < string.length; i += 1) { // console.log(string[i]); From 21e3f6daae5635b3f3b83c597d0768171af23318 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CAlexi?= <“alexi56”@comcast.net> Date: Tue, 18 Jun 2024 20:02:54 -0600 Subject: [PATCH 12/26] Week 1 day 2 --- 01-week/2-day/scratch.js | 72 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) diff --git a/01-week/2-day/scratch.js b/01-week/2-day/scratch.js index e69de29..1e11460 100644 --- a/01-week/2-day/scratch.js +++ b/01-week/2-day/scratch.js @@ -0,0 +1,72 @@ +//Array methods +//Methods are functions they're a just little different +//Instead of just calling it funcName() + +//methods are called after something string.toUpperCase() + +//Array methods are methods that called on arrays + +//push, pop, shift, unshift, splice, slice, split, and join + +let fruit = ["Apple", "Cherry", "Goji", "Mango", "Lemon", "Lime"]; + +//PUSH - Arguably the most commonly used array method +//Push adds an item(s) to the end of an array + +//Push returns the length of the array console.log(fruit.push("Cantaloupe", "Banana")) +let newFruitlength = fruit.push("Cantaloupe", "Banana") +//console.log(fruit) +//console.log(newFruitlength) + +//POP - Removes the LAST item in an array and returns the item it removed + +let lastFruit = fruit.pop() +//console.log(fruit) + +//console.log(lastFruit); + +let emptyArr = []; + +//console.log(emptyArr.pop()) //undefined + +//UNSHIFT - Adds items to the beginning of the array + +fruit.unshift("Strawbies"); +//console.log(fruit) + +//SHIFT - removes the FIRST item in an array + +let firstItem = fruit.shift(); +console.log(fruit) + +//console.log(firstItem) + +//SPLICE - Remove, replace, or add items to the original array +fruit.splice(1, 1); // Remove cherry start at index 1 and remove 1 item + +fruit.splice(3, 0, "Peach", "Pear") + +fruit.splice(3, 2) + +console.log(fruit) +//SLICE - We read mdn go look at it + +//Split and Join + +//Split is a STRING method +//Split takes a string and splits it into baby strings based on a pattern and puts the baby strings +//into an array + +//Most commonly used to iterate over a string + +let sentence = "The quick brown fox jumps over the lazy dog."; + +let stringArr = sentence.split(' '); + +for (let i = 0; i < stringArr.length; i++) { + console.log(stringArr[i]) +} + +//JOIN - concatenates an array + +console.log(stringArr.join('-')) \ No newline at end of file From 1716c53ee5b09c489ffda0c23bad7a3c68128a48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CAlexi?= <“alexi56”@comcast.net> Date: Thu, 20 Jun 2024 20:01:20 -0600 Subject: [PATCH 13/26] Week 1 day 4 --- 01-week/4-day/scratch.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/01-week/4-day/scratch.js b/01-week/4-day/scratch.js index e69de29..7b0c359 100644 --- a/01-week/4-day/scratch.js +++ b/01-week/4-day/scratch.js @@ -0,0 +1,19 @@ +//Nested Loops + +let fruit = ["Apple", "Orange", "Lemon", "Lime", "Blueberry", "Cherry"]; + +//Nested loop that console logs every unique pair of fruits + +//IMPORTANT - For every iteration of the outer loop, the inner loop must complete ALL +// of its iterations + +for (let i = 0; i < fruit.length; i++) { + let fruit1 = fruit[i]; + + //Write an inner loop + for (let j = i + 1; j < fruit.length; j++) { + let fruit2 = fruit[j]; + console.log(fruit1, fruit2) + } +} + From 3dcc71cafcf82c771a2e48ef8dba43f960829fd2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CAlexi?= <“alexi56”@comcast.net> Date: Tue, 25 Jun 2024 15:38:48 -0600 Subject: [PATCH 14/26] week 1 day 5 --- 01-week/5-day/scratch.js | 107 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 107 insertions(+) diff --git a/01-week/5-day/scratch.js b/01-week/5-day/scratch.js index e69de29..0290c80 100644 --- a/01-week/5-day/scratch.js +++ b/01-week/5-day/scratch.js @@ -0,0 +1,107 @@ +//Nested Arrays - Arrays within arrays + +let array = ["sheep", "cows", ["maincoon", "bombay", "tuxedo"], "fish"]; + +//console.log(array[2][1]); //"bombay" + +let arr2 = [1, 2, 3, [4, 5, 6, [7, 8, 9]]]; + +//console.log(arr2[3][3][1]); //8 + +let listOfFruits = [["Orange", "Lemon", "Lime"], ["Strawbie", "Bluebie", "BlackBerrie"], ["watermelon", "canteloupe"]]; + +//console.log(listOfFruits[1][0]) //Strawbie + +//Nested Loopies + +/* +A loop within a loop + +For every ONE iteration of the outer loop, the inner loop must complete all iterations + +The inner loop must complete all iterations before the outer loop can loop again + +The INNER LOOP MUST STOP before the outer loop can run again +*/ + +// for (let i = 0; i < 5; i++) { +// console.log("OUTER LOOP ITERATION: ", i); + +// for (let j = 45; j < 50; j++) { +// console.log("innerloop iteration: ", j) +// } + +// } + +// let sentence = "Crazy I was crazy once they locked me in a room a room with rats"; + +// let wordsArr = sentence.split(' '); + +// for (let i = 0; i < wordsArr.length; i++) { +// let word = wordsArr[i]; + +// for (let j = 0; j < word.length; j++) { +// console.log(word[j]); +// } +// } + +//Animal fightblub + +let animals = ["rat", "poyo", "tiger", "giraffe", "my husband", "creeper", "King"]; + +//I want a list of animal fights, whos fighting who? +//The outer loop is gonna grab an animal, the inner loop is gonna grab every animal after that one +// console.log("FIGHT LIST: ") +// for (let i = 0; i < animals.length; i++) { +// let animal1 = animals[i]; + +// for (let j = i + 1; j < animals.length; j++) { +// let animal2 = animals[j]; + +// console.log(animal1, animal2); +// } +// } + +//There are a couple ways to declare functions +//Function Expressions - when we set a variable equal to a function, and to call the function we call the variable name + + +/* +Regular func declaration +function funcName() { + //Code inside func +} +funcName() + + +Function expression: + +let funcName = function() { + +} +funcName() +*/ + +//When using function expression syntax, the function is considered anonymous because it doesn't have a name +// The only way to call it is to use the variable name that its inside of + +//FUNCTION EXPRESSION AND FUNCTION DECLARATIONS ARE THE SAME +let sayHi = function(name) { + console.log(`Hi ${name}!`); +} + +sayHi("Poyo"); + +// function doMath(num1, num2) { +// return num1 + num2 ; +// } + + +sayHi = function(name) { //REASSIGNING IT TO A NEW FUNC + console.log(`Bye ${name}.`) +} + +sayHi("Rat") + +let fruit = "apple"; +fruit(); \ No newline at end of file From 4b17dd5852a2bc2c4c448e1ab78805621f9e1a5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CAlexi?= <“alexi56”@comcast.net> Date: Tue, 25 Jun 2024 18:21:59 -0600 Subject: [PATCH 15/26] week 2 day 2 --- 02-week/2-day/scratch.js | 172 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 172 insertions(+) diff --git a/02-week/2-day/scratch.js b/02-week/2-day/scratch.js index e69de29..ab0b8df 100644 --- a/02-week/2-day/scratch.js +++ b/02-week/2-day/scratch.js @@ -0,0 +1,172 @@ +//Write a function findMax that takes in an array as an argument and returns +//the maximum number + +function findMax(arr) { + let max = null; + + for (let i = 0; i < arr.length; i++) { + let subArray = arr[i]; + + for (let j = 0; j < subArray.length; j++) { + if (subArray[j] > max) { + max = subArray[j]; + } + } + + } + + return max; +} + +//console.log(findMax([[1, 2, 3, 4], [5, 56, 65], [34, 25, 89, 34, 34, 24]])) //89 + + +//Helper Functions - When we call a function inside another function + +//SRP - Single Responsibility Principle +//The idea that every function in Javascript should have only ONE job and do that one job well + +//Why? It allows for easier debugging, easier maintainability, quicker changes to the program + +//Whichever function is the HELPER should exist before you use it +//AKA its declaration should be above wherever it is called + +// let apple; + + +// function sayHi(name) { +// //Any variable declared within CURLY braces DOES NOT exist outside of them (generally) +// let pear; +// } + +//HELPER FUNCTIONS + +//Helper function + +//Takes in a string and returns it as uppercase +///THIS IS THE HELPER FUNCTION +function yellStr(str) { + return str.toUpperCase(); +} + +//Create a new array with all strings from the old one in uppercase +function arrOfStrings(arr) { + let result = []; + + for (let i = 0; i < arr.length; i++) { + let string = arr[i]; + + let upperCaseStr = yellStr(string); + + result.push(upperCaseStr); + } + + return result +} + +// console.log(arrOfStrings(["apple", "pear", "lemon", "lime"])); + +// console.log(yellStr("barnacle")); + +//TERNARY OPERATOR - A shorthand for an if else statement + +//NORMAL WAY - + +// if (5 < 4) { +// console.log("Wooo"); +// } else { +// console.log("aww") +// } + +//Ternary - +/*The first item is the condition, the expression after the ? is what to run if its true, and the +expression after the : is what to run if its false + +TERNARIES DO NOT HAVE ELSE IF STATEMENTS +*/ +//(5 > 4) ? console.log("Wooo") : console.log("aww") + +//Objects - Is similar to an array except each item is labelled by what we call a key +// Objects are denoted by {} typically used for related data + +//An array - +//let king1 = ["King", 13, "likesTreats", "evil"] + +//Objects use key/value pairs and the keys are similar to variables, they are not strings +/* +OBJECT SYNTAX + +{ + key: value, + key: value +} +Key/value pairs are referred to as properties +Keys are like variables, values must be actual javascript data types +*/ + +let king = { + name: "King", + age: 13, + likesTreats: true, + friendly: false, + toys: ["mouse", "feather", "catnip"] +} + +//console.log(king) + +//Accessing items within an object: we use the keys +//Two different ways to access values using keys + +//The first way is VERY similar to indexing +//OBJECTS DO NOT HAVE INDICES + +// console.log(king["name"]) //BRACKET NOTATION objectName["keyname"] -> value + +//Second way to access values: + +// console.log(king.name) //DOT NOTATION objectName.keyname + +//How do we change values? + +//BRACKET NOTATION REASSIGNMENT: +king["age"] = 12; +// console.log(king); + +//DOT NOTATION REASSIGNMENT + +// king.likesTreats = false +// console.log(king); + +//Key names can't be changed, but their values can +//Keys can be deleted and new keys can be added + +//Add a key + +//BRACKET NOTATION ADDING KEYS/VALUES + +king["healthy"] = true; +// console.log(king); + +//DOT NOTATION + +king.color = "black and white"; +// console.log(king); + +//Accessing a specific toy + +//First get his toys + +king.toys.push("sushi") + +console.log(king.toys); + +console.log(king) + +// let arr = [1, 2, 3, 4, {name: "King", age: 12}] +// console.log(arr) + +//To delete a key use the delete keyword: + +delete king.healthy + +console.log(king); From 6a35f6b0eb4cdcbd2810c561e8cece7311ace0b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CAlexi?= <“alexi56”@comcast.net> Date: Wed, 26 Jun 2024 17:33:25 -0600 Subject: [PATCH 16/26] week 2 day 3 --- 02-week/3-day/scratch.js | 132 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 132 insertions(+) diff --git a/02-week/3-day/scratch.js b/02-week/3-day/scratch.js index e69de29..6fe70b5 100644 --- a/02-week/3-day/scratch.js +++ b/02-week/3-day/scratch.js @@ -0,0 +1,132 @@ +//Other types of FOR loops: + +//Regular for loop + +//let arr = ["apple", "pear", "cherry", "lemon"] + +// for (let i = 0; i < arr.length; i++) { +// console.log(arr[i]) +// } + +//For .. of +//Only works on arrays and strings +// for (let fruit of arr) { +// console.log("LOOP TWO",fruit) +// } + +//For .. in +//A for .. in loop is used to iterate over the KEYS of an object + +//Do ... while +//Almost exactly the same as a regular while except it will execute at least one time +//guaranteed + +// do { +// //CODE TO EXECUTE ONCE AND THEN HOPEFULLY REPEAt +// } while (condition to keep executing it) + + +//DETERMINING TYPES + +// let cat = 'king'; + +// let catAge = 456; + +// let bool = true; + +// //typeof operator returns the data type of stuff + +// console.log(typeof cat) //string +// console.log(typeof catAge) //number +// console.log(typeof bool) //boolean + +// //This can help us prevent JS from doing weird stuff +// if (typeof catAge === 'number') { +// console.log(catAge + 1000) +// } + +// let arr = ["apple", "pear", "cherry", "lemon"] + +// // Array.isArray(theArrayToCheck); +// //Will return a boolean + +// console.log(Array.isArray(cat)); + +//Function expressions + +//Assigning a variable to an anonymous function +//And to call the function you use the variable name + +let apple = function(fruit2) { + console.log("apple", fruit2) +} + +//apple() + + +//Helper functions +//Is just a function that happens to be being called in another functions declaration + +function doesStuff(name) { + console.log(`Hi, ${name}`); + + 4+4; + let arr = ["guava"] + + apple(arr[0]); + /* + function(arr[0]) { + console.log("apple", arr[0]) + } + */ + + return "barnacle" +} + +//console.log(doesStuff("pickles")) + + +// apple("lemon") + +//SCOPE - +//Where do things exist and where do things not exist? +//Global, local/function, block scopes +//console.log(dog) Can't access variables above either + + +//INNER SCOPES CAN ACCESS VARIABLES DECLARED IN OUTER SCOPES +//BUT OUTER SCOPES CANNOT ACCESS VARIABLES DECLARED IN INNER SCOPES + +//Global - Can be accessed (exists in) by literally everything +// let dog = "onyx"; + +// function sayHi(name) { +// //Name only exists within these curly braces and not outside +// let fruit4 = "Lime" //Fruit4 ^^ +// console.log(name); + + +// if (5 > 4) { +// let barnacle = "barnacle"; + +// console.log(fruit4); +// fruit4 = "Peach" + +// console.log(dog) +// } +// console.log(fruit4) + + +// for (let i = 0; i < 4; i++) { +// //Block scope +// let animal = "ostrich" +// console.log(barnacle) +// } +// console.log(animal) +// //console.log(barnacle) //Trying to access an inner scoped variable from an outer scope +// } + +// sayHi("King") +// //console.log(name) //Trying to use name in a scope where it doesn't exist +// console.log(fruit4) + From 031441d564e3e425e14721ff200114ebc5b3657c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CAlexi?= <“alexi56”@comcast.net> Date: Thu, 27 Jun 2024 19:51:17 -0600 Subject: [PATCH 17/26] week 2 day 4 --- 02-week/4-day/scratch.js | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/02-week/4-day/scratch.js b/02-week/4-day/scratch.js index e69de29..1563e7b 100644 --- a/02-week/4-day/scratch.js +++ b/02-week/4-day/scratch.js @@ -0,0 +1,35 @@ +//Break operator and the continue operator ONLY for loops + + +// let arr = ["apple", "pear", "lemon", "lime"]; + +// //The break operator will stop a loop + +// //the continue operator won't break out of the loop entirely, just stop the current iteration + +// for (let i = 0; i < arr.length; i++) { +// console.log(arr[i]) +// if (arr[i] === 'pear') { +// //break; //ends the loop entirely +// //continue; //ends the current iteration +// } +// console.log(arr[i]) +// } + +// while (true) { +// continue; +// console.log("woooo") //never happens, but loop is still looping +// } + +// let users = ["bobby", "mary", "joe", "barnacle"]; + +// for (let i = 0; i < users.length; i++) { +// let user = users[i]; + +// if (user === 'mary') { +// continue; +// } + +// //DELETE USER FROM DATABASE +// console.log(`${user} was successfully deleted.`) +// } \ No newline at end of file From 749335561c346f5272bbfcb36b647b0d04119a21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CAlexi?= <“alexi56”@comcast.net> Date: Mon, 8 Jul 2024 20:01:32 -0600 Subject: [PATCH 18/26] week 3 day 1 --- 03-week/1-day/scratch.js | 199 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 199 insertions(+) diff --git a/03-week/1-day/scratch.js b/03-week/1-day/scratch.js index e69de29..62ec47b 100644 --- a/03-week/1-day/scratch.js +++ b/03-week/1-day/scratch.js @@ -0,0 +1,199 @@ +//INTRO TO OBJECTS +//A collection of (normally) related items stored in key/value pairs +//Stores data very similarly to an array, every key/value pair is separated by a comma + +//Objects are denoted by {} + +/* +We use the keys to get the values + +Keys are very similar to variables, they're just a label with which we can find a value + +Values can be ANY data type! + +OBJECTS DO NOT HAVE INDICES - Objects do not have any inherent order + Also relates to why we cannot change keyNames + +SYNTAX + +{ + keyName: value, + otherKeyName: otherValue +} +*/ + +//Sample object +// let cat = { +// name: "King", +// age: 13, +// likesTreats: true, +// toys: ["sushi", "mouse", "string"] +// } + +//console.log(cat); + +//How could we access individual values from an object +//We have two methods: bracket and dot notation + +//Bracket notation - objectName["keyName"] + +// console.log(cat["name"]); //King + +// //Dot notation - objectName.keyName + +// console.log(cat.age) // 13 + +//Console log sushi +//console.log(cat.toys[0]) + +// let cat = { +// name: "King", +// age: 13, +// likesTreats: true, +// toys: ["sushi", "mouse", "string"] +// } + +//Reassigning object values +//We can again use bracket or dot notation +//VERY similar to variable reassignment + +//cat.likesTreats = false; //DOT NOTATION + +//cat["likesTreats"] = false; //BRACKET NOTATION + +//cat.name = "Kingifer" + +//ADD ITEMS TO AN OBJECT +//Its again just like reassignment +//We can again use bracket or dot notation + +//cat.color = "black and white"; + +//console.log(cat) + +//You cannot change KEYS, you must instead delete them and add a new one + +//To delete a key (key/value pair) -> delete objectName.keyName || delete objectName["keyName"] + +// delete cat.toys + +// console.log(cat) + +//How add another toy -> toys is an array + +// let cat = { +// name: "King", +// age: 13, +// likesTreats: true, +// toys: ["sushi", "mouse", "string"] +// } + +// cat.toys.push("feather"); + +// console.log(cat); + +// cat.nickName = cat.name + 'y'; + +// cat["veryCute"] = true + +// console.log(cat) + + + +//Function declaration syntax +/* +function funcName() { +//Code +} +funcName() +*/ + +//Function expression syntax +//We are able to do this because functions are considered first class objects +//It can live inside of a variable +/* + +let funcName = function() { + //CODE +} +funcName() +*/ + +// let hello = function(name) { +// console.log("Hey, " + name) +// } + +// hello("King") + +// let cat = { +// name: "King", +// age: 13, +// likesTreats: true, +// toys: ["sushi", "mouse", "string"], +// meow: function() { +// console.log("meowwwww my name is " + cat.name) +// } +// } + +//We can put functions into objects, but then we call them something different +//We call them METHODS + +//cat.meow(); + +//Way to check if a key exists in an obj + +//IN operator - tells us if a key exists within an object with a boolean + +// console.log("meow" in cat) + +// console.log("paws" in cat) + +//console.log("admin" in user) + +//FOR LOOPS + +let cat = { + name: "King", + age: 13, + likesTreats: true, + toys: ["sushi", "mouse", "string"], + meow: function() { + console.log("meowwwww my name is " + cat.name) + } +} + +//We can use for ... in loop to iterate over the KEYS of an obj +/* +if we're looping through the keys, and we can use the keys to access values +we can then iterate through the values + +//SYNTAX +KEY can be named anything but it will ALWAYS contain the keys +for (let KEY in objectName) { + //Code to repeat +} +*/ +//When you want to use a variable to access a property within an obj, you cannot use dot notation +//you have to use bracket notation + +// for (let key in cat) { +// //console.log(key) THIS GIVES US THE KEYS +// //KEY is a variable, it exists OUTSIDE of the object +// //cat.key is a different thing, its going into cat and looking for a key property + +// console.log(cat[key]) //ex: cat["name"], cat["age"], etc +// console.log(cat.key) // ex: cat["key"] or cat.key +// } + +let car = { + make: 'BMW', + model: 'M3', + color: 'blue', + year: 2024, + rust: true, + transmission: 'manual', + mileage: 17000, + features: ["apple carplay", "rats", "backup cam", "heated/leather seats", "jacuzzi"] +} + +console.log(car.features[4]) // jacuzzi \ No newline at end of file From 4577b0ec68d5b81268ec2f2178dcd548be1a2781 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CAlexi?= <“alexi56”@comcast.net> Date: Thu, 11 Jul 2024 20:01:33 -0600 Subject: [PATCH 19/26] week 3 day 4 --- 03-week/2-day/scratch.js | 173 +++++++++++++++++++++++++++++++++++++++ 03-week/3-day/scratch.js | 89 ++++++++++++++++++++ 03-week/4-day/scratch.js | 111 +++++++++++++++++++++++++ 3 files changed, 373 insertions(+) diff --git a/03-week/2-day/scratch.js b/03-week/2-day/scratch.js index e69de29..d83f106 100644 --- a/03-week/2-day/scratch.js +++ b/03-week/2-day/scratch.js @@ -0,0 +1,173 @@ +//Function declaration syntax: +/* + +function funcName() { + //CODE +} +funcName(); +*/ + +//Function expression syntax - Assigning an anonymous function to a variable +/* + +let funcName = function() { + //CODE +} +funcName() +*/ + +//Arrow functions +/* +They DO NOT use the function keyword +() => {} + +If you only have ONE parameter you can actually omit the parenthesis +if the arrow function has only one expression or statement, you can omit the curly braces! and this will cause +an implicit return (returns without the keyword). +You can only do these fun little tricks with arrow functions +If you have ZERO parameters you MUST have the parenthesis + +let arrowFunc = (parameters) => { + //CODE +} +arrowFunc(arguments) +*/ + +// let sum = (num1, num2) => { +// return num1 + num2; +// } + +//console.log(sum(9, 8)); + +// function hello(name) { +// return `Hello ${name}!` +// } + +// hello('King') + +//let hello = name => `Hello ${name}!`; //Implicit return + +//console.log(hello('King')); + +//let sum = (sum1, sum2) => sum1 + sum2; + +//console.log(sum(45, 67)) + +// let arrow = () => { +// return "arrow" +// } + +// let favColor = (color) => { + +// if (color === 'blue') { +// console.log("blue!") +// } else if (color === 'pink') { +// console.log("Pink!") +// } else { +// console.log(`Whoa bro you like ${color}?`) +// } + +// for (let i = 0; i < 5; i++) { +// console.log(color) +// } +// } + +// favColor('yellow') + +/* + +OBJECT SYNTAX +The keys are similar to variables/strings +the values can be any valid JS data type: arrays, strings, numbers, booleans, objects, null, undefined, functions +Object keys cannot start with a number + +let variableName(objname) = { + keyName: value, + otherKey: otherValue +} + +If we want to access the VALUES of an object we have to use the KEYS +*/ + +// let car = { +// make: 'Ferrari', +// model: '488', +// year: 1837, +// mileage: 2, +// rust: false, +// features: ['horse drawn', 'seats', 'cd player', 'muskets', 'apple car play', 'dubloons'], +// headlights: null +// } + +//console.log the year of this car +//Two different ways: dot notation and bracket notation + +//Dot notation +//console.log(car.year); + +//Bracket notation - Unless we are putting a VARIABLE into the brackets we must have quotes around the key +//Key Example: +//console.log(car["year"]); //We are using the literal key + +//Variable example: + +let keyName = 'year'; +//console.log(car[keyName]); //We are using a variable + +//We CANNOT use variables with DOT NOTATION +//console.log(car.keyName) //This isn't treating like a variable its treating it like a key +//If you want/need to use a variable as key to access a value YOU MUST USE BRACKET NOTATION + +//REASSIGNING PROPERTIES - Dot or bracket +// console.log(car) +// //Dot notation: +// car.mileage = 1000000 +// console.log(car); + +// car["mileage"] = 4 +// console.log(car); +//Write a function that takes in a car (object), takes in the property that we need to update, and the new value of that property + +let updateCarData = (carObj, keyToUpdate, newValue) => { + //keyToUpdate is a parameter (basically just a variable) + carObj[keyToUpdate] = newValue; + return carObj; +} + +let car = { + make: 'Ferrari', + model: '488', + year: 1837, + mileage: 2, + rust: false, + features: ['horse drawn', 'seats', 'cd player', 'muskets', 'apple car play', 'dubloons'], + headlights: null +} + +// console.log(updateCarData(car, 'rust', true)) + +// for (let i = 0; i < 5; i++) { +// console.log(i) +// } + +//Looping "through" an array + +let fruit = ["apple", "cherry", "lemon", "lime", "orange", "blueberry", "guava", "pear", "fruit", "fruit", "fruit"]; + +//Console log every item in the fruit array + +// console.log(fruit[0]) //apple +// console.log(fruit[1]) //cherry +// console.log(fruit[2]) //lemon +// console.log(fruit[3]) //lime +// console.log(fruit[4]) //orange + +//Instead of doing this^^ We can take advantage of a loop that counts and do this: + +console.log(fruit.length) + +for (let i = 0; i <= fruit.length - 1; i++) { + //console.log("VALUE OF i", i) + console.log(fruit[i]) +} + \ No newline at end of file diff --git a/03-week/3-day/scratch.js b/03-week/3-day/scratch.js index e69de29..d0a3958 100644 --- a/03-week/3-day/scratch.js +++ b/03-week/3-day/scratch.js @@ -0,0 +1,89 @@ +// let arr1 = [1, 2 ,3 ,4]; + +// let arr2 = arr1; + +// let arr3 = arr1; + +// let arr4 = arr3; + +// arr1[1] = 'barnacle'; + +// arr2[3] = 456; + +// arr3.push('rat'); + +// console.log(arr1, arr2, arr3, arr4); + +//^^^These get manipulated because we're assigning the new variables to +//existing ones (variables that contain reference types) + +// let arr1 = [1, 2 ,3 ,4]; + +// let arr2 = [1, 2 ,3 ,4]; + +// arr1[1] = 'barnacle' + +// console.log(arr1, arr2) +//^^ These do not get manipulated because THEY ARE NOT assigned to variables + +//THIS EFFECT DOESNT HAPPEN WITH PRIMITIVE/IMMUTABLE DATA TYPES + +// let num1 = 45; + +// let num2 = num1; + +// num1 += 7 + +// console.log(num1, num2) + +//OBJECTS + +let mikeJonesRat = { + name: 'cheese', + age: 0o1, + hair: 'afro', + occupation: 'cook', + friends: ['Mike Jones', 'batman', 'turtles', 'Remy', 'tom cruise', 'Biggie Smalls'], + mean: true, + cookinUp: function(ingredients) { + console.log(`${mikeJonesRat.name.toUpperCase()} whipped up a great meal with ${ingredients}.`) + }, + hello: (buddy) => { + for(let i = 0; i < 5; i++) { + console.log("Nice to ya") + } + console.log('SO GOOD TO SEE YA ' + buddy) + }, + lying: () => { + if (mikeJonesRat.mean) { + console.log("I'm very nice") + } else { + console.log('No, my gosh I am not mean!') + } + } +} + +//console.log(mikeJonesRat); + +//METHODS - A method is simply a function that belongs to an object +//To create a method you add a key and the value is a function + +//How do we call a method? +// objectName.methodName() +//objectName["methodName"]() + +// mikeJonesRat["cookinUp"]('pear, garlic, and broccoli') + +// mikeJonesRat.hello("King") + +// mikeJonesRat.lying(); + + +// let outerHello = mikeJonesRat.hello; + +// outerHello("BuddyOlePal") + +//Object.keys(objectName), Object.values(objectName), Object.entries(objectName) + +console.log(Object.keys(mikeJonesRat)) +console.log(Object.entries(mikeJonesRat)) diff --git a/03-week/4-day/scratch.js b/03-week/4-day/scratch.js index e69de29..2a748ec 100644 --- a/03-week/4-day/scratch.js +++ b/03-week/4-day/scratch.js @@ -0,0 +1,111 @@ +//Rest, spread, and destructuring! + +//REST + +//Functions in JS can accept as many or as few arguments as you want + +//Passing more arguments into a function than it expects + +//The REST operator (...) allows us to grab the "rest" of the arguments (any additional argument) +//The rest operator must be the last argument + +// let sum = (num1, num2) => { +// return num1 + num2 +// } + +// console.log(sum(5, 6, 7, 7, 8)) + +//Using rest (...) THE REST OPERATOR IS IN THE PARAMETERS of a function + +//syntax ...parameterName -> will be an array + +let sayHiToFriends = (person, mom, ...friends) => { + console.log(`${mom} says hi to all of ${person}'s friends: `); + + console.log(friends) + for (let i = 0; i < friends.length; i++) { + console.log(friends[i]) + } +} + +//sayHiToFriends('Greg','Debby', 'jill', 'goobles', 'thorton'); + +//Spread operator (...) is used with arrays and objects +//Copies arrays and objects +//Spread operator creates a deep copy of arrays and objects + +let numArr = [1, 2, 3, 4]; + +//Copy arrays + +let copyArr = [...numArr]; + +//numArr[0] = 9 + +//console.log(copyArr) + +//Deep copy vs a shallow copy +//A deep copy does not point to the same place in memory +//A shallow copy means that there is now another thing pointing to the same place + +let newArr = [...numArr, 5, 6, 7, 8]; + +//console.log(newArr); + + +//Destructuring - Objects and arrays can be destructured + +//OLD WAY TO CREATE VARIABLES FROM ARRAYS + +let fruit = ['apple', 'orange', 'lemon', 'lime'] + +let apple = fruit[0]; +let orange = fruit[1]; +let lemon = fruit[2]; +let limeGuy = fruit[3]; + + +//Array Destructuring syntax: let [variables] = arrayName +//Create four variables apple2, orange2, lemon2, lime2 and get their values from the fruit array' +//For ARRAY destructuring JS assigns the values based on what index the variables are in + + +let [apple2, orange2, lemon2, lime2] = fruit; + +//console.log(orange2) + + +//OBJECT destructuring: let {variables} = objectName + +let cat = {name: 'apples', breed: 'diva'}; + +//The variables MUST be named the keys in which you want the values of + +//We have two new variables name and breed +let { name, breed } = cat; + +//Name is its own variable that IS NOT connected to an object (it just got its value from an object) +name = 'pickles' //Reassigning the name variable ONLY +console.log(name) + +console.log(cat) + +cat.name = 'jerry' //Reassigning the CAT OBJECTS name property + + +console.log(cat) + + +let userFromProfileComponent = { firstName: 'bob', lastname: 'bobert', email: 'bob@bob.com', password: 'password'}; + + +//THIS IS GROSS +console.log(userFromProfileComponent.name); +console.log(userFromProfileComponent.lastname) + +//INSTEAD DESTRUCTURE INTO TINY VARIABLES + +let { firstName, lastname, email, password } = userFromProfileComponent + + +console.log({} + {}) \ No newline at end of file From 154703e320bc3dad58ac9fda911468d3a44c62af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CAlexi?= <“alexi56”@comcast.net> Date: Fri, 12 Jul 2024 20:03:08 -0600 Subject: [PATCH 20/26] week3 day 5 --- 03-week/5-day/scratch.js | 104 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 104 insertions(+) diff --git a/03-week/5-day/scratch.js b/03-week/5-day/scratch.js index e69de29..de069c0 100644 --- a/03-week/5-day/scratch.js +++ b/03-week/5-day/scratch.js @@ -0,0 +1,104 @@ +//Rest +//Rest parameter will grab the REST of the arguments passed into a function and put them all into an array +//The rest parameter must be the last one + +function sum(...nums) { //(...nums) will grab all arguments passed into the function and put them into an array called nums + let sum = 0; + + for (let i = 0; i < nums.length; i++) { + sum += nums[i]; + } + + return sum; +} + +//console.log(sum(5, 6, 7, 8, 9)); + +//Spread +//Spread copies items from an array or an object that we can move elsewhere + +//Spread creates a deep copy of arrays or objects, but only on the top level. Nested arrays or objects +//will be shallow +//Takes items one by one, copies them, and puts them in a new location + +let arr = [1, 2, 3, 4, [true, false]]; + +let copyArr = [...arr]; + +arr[0] = 'beep' + +arr[4][0] = 'BOO' + +//console.log(arr, copyArr) + +//Using spread on objects + +let cat = {name: 'apples', breed: 'tabby'}; + +let copyCat = { ...cat, eyeColor: "yellow", age: 1 }; + +//console.log(copyCat) + + + +function sayHi(person, friend) { + console.log(`${person} says hi to ${friend}`); +} + +let people = ["Greg", 'Ralph']; + +//sayHi(...people) + +//Destructuring +//A quick way to create variables from values within arrays or objects +//Destructuring creates SHALLOW copies + +// let fruit = ["apple", "orange", "lemon", "lime", [1, 2]]; + +//OLD WAY, TEDIOUS, GROSS +// let appleGuy = fruit[0]; +// let orangeGuy = fruit[1]; + +//ARRAY DESTRUCTURING WAY: +//let [ pickles, jam, potato, , greenbean ] = fruit; //Each of these variables will get their values from the corresponding +// index in the fruit array + +// greenbean[1] = 'BOOOO' + +// console.log(greenbean) +// console.log(fruit) + +//OBJECT DESTRUCTURING + +//DRY - Don't Repeat Yourself +// let bob = { firstName: 'bob', lastName: 'bobert', email: 'bob@bob.com', password: 'password'} + +//NOT DRY CODE +// console.log(user.firstName); +// console.log(user.lastName); +// console.log(user.password); + +// let userFromProfileComponent = { name: 'ralph', age: 107} +// //UGLY AND HARD TO READ +// console.log(userFromProfileComponent.name); +// console.log(userFromProfileComponent.age) + + +//INSTEAD OF THAT^^^ +//We can destructure + +//OBJECT DESTRUCTURING +let bob = { firstName: 'bob', lastName: 'bobert', email: 'bob@bob.com', password: 'password'} + +//Lets create some tiny crisp variables with bobs info + +//Here we're creating each of these variables but their names match the keys +//What if we wanted to create a variable with a different name +//let { firstName, lastName, email, password } = bob; + +//ALIASING +let { firstName: firstName, lastName: bobsLName, email, password } = bob; + +//console.log(firstName); //Doesn't exist because we gave it an alias of 'bobsFName' + + From 3258b909871a1c114bc0344713bf46853609d0f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CAlexi?= <“alexi56”@comcast.net> Date: Tue, 16 Jul 2024 18:00:07 -0600 Subject: [PATCH 21/26] Week 4 Day 1 --- 04-week/1-day/scratch.js | 177 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 177 insertions(+) diff --git a/04-week/1-day/scratch.js b/04-week/1-day/scratch.js index e69de29..53bd1dd 100644 --- a/04-week/1-day/scratch.js +++ b/04-week/1-day/scratch.js @@ -0,0 +1,177 @@ +//Callbacks +//Using a function as an argument +//Functions are first class objects which allows us to store them inside of variables, and this also +//allows us to pass them into other functions as arguments + +//Advanced Array Methods like .map(), forEach(), and .filter() all accept callback functions as parameters + +//If you have a function that has a parameter that is being used as a function (expecting a func) that is a callback + +//REMINDER - helper functions and callback functions ARE REGULAR FUNCTIONS its just how we are using them +// that gives them a different + +//Helpers are static used when it will never change, Callbacks are dynamic use when you may want to pass in different funcs + +//Helper functions are called inside of functions (but you're always calling the same one) +//ex: + +//Takes in two numbers and adds them together +function sum(num1, num2) { + return num1 + num2; +} +//Iterates through array and calls sum on each element +function addsTwoToArrNum(arr) { + let result = []; + for (let i = 0; i < arr.length; i++) { + result.push(sum(arr[i], 2)) //THIS IS A HELPER FUNCTION BECAUSE IT NEVER CHANGES + } + + return result; +} + +//Callback functions, however, are passed in as arguments to a function so you can use different functions +//within the outer one +//Ex: + +let sayHi = () => { + console.log('Hello World') +} + +let sayBye = () => { + console.log('Goodbye World') +} + +//Lets define a function that "takes in a callback" + +function saySomething(callback) { + console.log("Before callback"); + + callback(); + + console.log("After callback"); +} + +//When we call this function we can pass in WHATEVER function we want into the place of "callback" + +// saySomething(sayHi) //When passing in a callback WE DO NOT CALL THE FUNCTION because that would pass in the RETURN statement + +// saySomething(sayBye) + +let double = (num) => { + return num * 2; +} + +let triple = function (num) { + return num * 3; +} + +function sum(x, y, cb) { + let sum = x + y; + + let result = cb(sum); + + console.log(result); +} + +// sum(2, 2, triple) // Triple as the callback (we are passing the triple function in) + +// sum(2, 2, double); //Double as the callback (we are passing the double function in) + +//Example with a helper AND a callback + +let cookingUp = (name) => { + console.log(`${name} the rat is cooking up.`) +} + +let ratatoulli = () => { + console.log(`Ratatoulli is served.`) +} + +let chickenNGnocci = () => { + console.log(`Chicken gnocci is served.`) +} + +//cookingUp('Guelrmo') + +//RATPARTY takes in a callback, and also uses a helper function +let ratParty = function (rat1, rat2, cb) { + console.log(`${rat1} welcomes you to the rat party!`); + + cookingUp(rat2); //CookinUp is a HELPER function bc it NEVER changes + //cookingUp is NOT a parameter it is a literal function name so it will never change + + //HERE WE ANNOUNCE WHAT DISH HAS BEEN SERVED FOR THIS RAT PARTY + cb(); //Here is the callback which will be whatever function we pass in (IT CAN CHANGE) + //The word cb is a parameter, it is storing a function that we are calling + //since cb is a parameter is could hold ANY function we want + + console.log(`Woooo parties over we got rat police otw`) +} + +// ratParty('Remy', 'Barnacle Boi', ratatoulli) //the ratatoulli function will be the callback for this function call + +// ratParty('Remy', 'guerlmo', chickenNGnocci)// the chickenGnocci function will be the callback for THIS function call + + +//REST - pattern that grabs the "rest" of the arguments +// Its most often used as a parameter but can also be used for destructuring to put the rest of the values into an array + +//The rest parameter grabs the rest of the arguments and PUTS THEM INTO AN ARRAY +function sayHiToFriends(person, mom, ...friends) { + console.log(`${person}'s mom ${mom} says hi to all their friends: `); + + for (let i = 0; i < friends.length; i++) { + console.log(friends[i]); + } +} + +// sayHiToFriends('Greg', 'Laura', 'Remy', 'Gerulmo', 'Borble'); +//Gerg will go into the person param, Laura will go into the mom param, and EVERY SUBSEQUENT ARGUMENT goes in to friends + +//SPREAD operator +//Makes copies of items from an iterable (object/array) and then moves them to another place +//The spread operator creates SHALLOW copies + +let arr = [1, 2, 3, 4]; + +let copyArr = [0, ...arr, 5, 6, 7]; + +// console.log(copyArr) + +//Copying reference types +//Reference vs Primitive data types +//Shallow vs Deep copies +//Shallow copy - all variables containing the copies point to the same place in memory, so if you change one you change them all +//Deep copy - points to its own place in memory so nothing else can effect it + +let fruit = ["apple", "grape", "watermelon", ["orange", "lemon", "lime"]]; + +let copyFruit = [...fruit]; // ANY REFERENCE TYPES that have been copied will be pointing to the same place in mem. + +fruit[3][1] = 'pomegranate'; + +console.log(copyFruit, fruit); + +//Destructuring Objects +//Its just a way to create variables from values of objects super quickly +let cat = { name: "King", age: 13, eyeColor: "Yellow", mean: true, petty: true } + +//OLD way to create variables +//Gets very tedious very quickly +//IS not DRY (dont repeat yourself) +let kingsName = cat.name; +let kingsEyeColor = cat.eyeColor; + +//Destructuring way: +//let {variables} = object +//The only way to find values within an object is to use the key names so by default +// our variables must share the same name as the keys we are trying to access + +//If we want our variable to have a different name than the key we're accessing we must use ALIASING + +//let { keyName: newName } = object + +let { name, eyeColor, petty: isKingPetty } = cat; +//name = "King", eyeColor = "yellow", petty = true + +console.log(name, eyeColor, isKingPetty) \ No newline at end of file From 177950191f6f08c3c9e96b7e60fbe1a31cb7203d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CAlexi?= <“alexi56”@comcast.net> Date: Tue, 16 Jul 2024 20:00:54 -0600 Subject: [PATCH 22/26] Week 4 Day 2 --- 04-week/2-day/scratch.js | 151 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 151 insertions(+) diff --git a/04-week/2-day/scratch.js b/04-week/2-day/scratch.js index e69de29..bc16d75 100644 --- a/04-week/2-day/scratch.js +++ b/04-week/2-day/scratch.js @@ -0,0 +1,151 @@ +//SCOPE - Where are variables accessible? +//Why? Security, Space, and Name collisions (two variables with the same name) + +//3 types of scope in JS +// Global, local/function, block + +//IMPORTANT: Inner scopes can access variables declared in outer scopes, but outer scopes +// cannot access variables declared in inner scopes + +//Global scope - +//Widest possible scope +//Everything is declared in the global scope +//Everything has access to variables declared "globally" (as long as we're accessing them below +//where they were declared) +//Global scope is typically not desirable; we use it as minimally as possible + +let fruit = 'apple' //Globally scoped variable (Hint: its not inside of curly braces) + +//Local/Function scope - +//Scope within a function +//Any variables declared within the function/parameters of the function are all locally scoped +//Variables that functions have access to: variables in the global scope, functions parameters +//variables declared within the function, any other variables declared in the scope above function + +//SCOPE CHAINING - When we use a variable in JS, JS will look for the value of that variable, and JS +// will start looking in the scope where the variable was used. If JS can't find the +// value in the current scope it'll go up to the next outer scope and so on until +// it finds a value. JS will stop looking when it finds a value + + +// let catName = "King"; + +// function sayName() { +// //let fruit2 = "pear" //fruit2 is locally scoped +// let catName = 'Bobert' + +// //console.log(catName); + + +// function greet() { +// console.log("Hi " + catName) +// } + + +// greet() +// } + +// function localScope(param) { +// console.log(param) +// } + +//console.log(param) //Parameters are local scoped + +// function sayName2() { +// console.log(catName) +// } + +// //console.log(fruit2) //Fruit2 is inaccessible from an OUTER scope of where it was declared + +// sayName() + + +//Block Scope - Any other curly braces (besides objects) +// For loops, while loops, if, else, and else if statements + +// if (true) { +// let fruit3 = "lemon"; //Fruit3 is BLOCK scoped again inaccessible by outer scopes +// console.log(fruit3) +// } + +// console.log(fruit3) + +// for (let i = 0; asdsadasdasdas) { +// //i is a block scoped variable +// } + +//Lexing time - JS first runthrough of the file before it executes anything +//During lexing time JS determines what variables and functions are declared and it determines +//what scope variables are in + +//The keyword you use to declare a variable changes its scope + +//var, let, and const +//each one is "scoped" differently + +//Let and const were created in 2015, before then VAR was the only option + +//VAR - enemy of the state +//Most people think that var is global scoped, it is, but its also function/local scoped +//If you declare a variable using var anywhere other than inside a function it will be accessible +//like a globally scoped variable +//YOU CAN ALSO DEFINE AS MANY VARS WITH THE SAME NAME AS YOU WANT + +//NO ONE USES VAR UNLES YOU WANT JAIL TIME + +//Declared a var variable within a block so it is globally scoped +// if (true) { +// var fruit3 = "lemon"; //Fruit3 is BLOCK scoped again inaccessible by outer scopes +// console.log(fruit3) +// } + +//console.log(fruit3) + +function hello() { + var bunny = 'bunny'; + console.log(bunny) + + var bunny = 'carrot'; + + console.log(bunny) +} + +//console.log(bunny) +//hello() + +//LET AND CONST +//Are both block scoped +//You cannot declare two lets with the same name + +//Let can be reassigned a new value const cannot +let carrot = 'carrot'; + +carrot = 'tomato'; + +//CONST CAN NEVER BE REASSIGNED +//const stands for constant + +const catName = 'King'; + +//catName = 'George'; + +//Before 2015 if we needed a constant in JS we would just name it in all caps +//Ex: +//var CONSTANT = 'bunny'; + +//Even though we now have const its still industry standard to capitalize constant variable names +const DATABASE_URI = 'asdasdsadsdasd' + +//If you assign a const variable to a reference type, you cannot reassign the variable +// but you can manipulate the object/array + +const CATGUY = { + name: "King", + age: 13 +} + +//CATGUY = [1, 2, 3] //CANNOT REASSIGN CATGUY + +CATGUY.treats = 'churu' + +console.log(CATGUY) \ No newline at end of file From 663e81ecf88a1a0d630e4b9fad04e0b55ab80208 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CAlexi?= <“alexi56”@comcast.net> Date: Wed, 17 Jul 2024 19:59:46 -0600 Subject: [PATCH 23/26] Week 4 day 3 --- 04-week/3-day/scratch.js | 110 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 110 insertions(+) diff --git a/04-week/3-day/scratch.js b/04-week/3-day/scratch.js index e69de29..e31607e 100644 --- a/04-week/3-day/scratch.js +++ b/04-week/3-day/scratch.js @@ -0,0 +1,110 @@ +//Closures +//A pretty common interview question +//A function that uses or manipulates variables declared +//in the function its inside of + +//Using the variable +// function outerFunc() { +// let fruit = 'apple'; + +// function innerFunc() { +// console.log(fruit) +// } + +// innerFunc() +// } + +// outerFunc() + +// function numberStuff() { +// let number = 10; + +// function addToNum() { +// number += 1; +// console.log(number) +// } + + +// return addToNum; +// } + +//number++ Number doesn't exist outside of the closure so we cant manipulate it out here +// let addToNumOutside = numberStuff(); //The return statement is the addToNumOutside function + +// addToNumOutside(); +// addToNumOutside(); +// addToNumOutside(); + +//One main reason why we use closures is when we have a variable that we only want to be manipulated in VERY +// specific ways. So we wrap that variable in a function, and then inside that function create more functions +// that manipulate the variable. Then we return those functions and now outside of the closure we can only +// manipulate the variable using those functions + +// function storeSocialSecurityNumber() { +// let ssn = 10; + +// function addFour() { +// ssn += 4; +// console.log(ssn); +// } + +// function minus9() { +// ssn -= 9; +// console.log(ssn) +// } + +// function addAnyNum(num) { +// ssn += num; +// console.log(ssn) +// } + +// return [addFour, minus9, addAnyNum] +// } + + +//Destructuring +//I want to create two variables, addFour and Minus9 and I'm taking their values from an array +// let [addFourOutside, minus9Outside, addAnyNumOutside] = storeSocialSecurityNumber() + +// //let functions = storeSocialSecurityNumber(); + +// // let addFour2 = functions[0]; + +// // let minus9 = functions[1]; + +// addFourOutside(); + +// minus9Outside(); + +// addFourOutside(); +// addFourOutside(); +// addFourOutside(); + +// addAnyNumOutside(100); + + +//A super common use of closures is when you have a variable that you want to keep private +//AKA you only want to manipulate it in very speicifc ways + +function fruitShop() { + let fruitList = ["apple", "lemon", "orange"]; + + function addFruitToList(fruit) { + fruitList.push(fruit); + console.log("Updated fruit list: " + fruitList) + } + + return addFruitToList; +} + + +//fruitList.push("Crime Guava") THIS CANT HAPPEN because fruitlist does not exist in the global scope + +let addToList = fruitShop(); // We assign addToList to the value of the addFruitToList function + +addToList("Guava"); + +addToList("Watermelon"); + +addToList("Kumquat"); + From 4d97a762e25f2e2dd26e979ed772a1e5f0070c76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CAlexi?= <“alexi56”@comcast.net> Date: Tue, 23 Jul 2024 20:00:17 -0600 Subject: [PATCH 24/26] Week 5 day 1 and 2 --- 05-week/1-day/scratch.js | 44 ++++++++++++++++++++++++++++++++++++++++ 05-week/2-day/scratch.js | 37 +++++++++++++++++++++++++++++++++ 2 files changed, 81 insertions(+) diff --git a/05-week/1-day/scratch.js b/05-week/1-day/scratch.js index e69de29..c007c82 100644 --- a/05-week/1-day/scratch.js +++ b/05-week/1-day/scratch.js @@ -0,0 +1,44 @@ +//Stack - A common data structure +/* +Similar to a stack of papers + +To add items onto a stack, you can only add onto the top of the stack +to remove items you can also only remove from the top of the stack + +FILO - First in, Last out + +Commonly stacks are imitated in javascript by pushing and popping on arrays +*/ + +//Call stack +//A structure used by Javascript to keep track of function calls +// (uses a stack data structure) +//CALL STACK - ONLY FOR FUNCTION CALLS + +/* + +When a function is CALLED, it is pushed onto the call stack + +Then, when a function RETURNS it is going to be POPPED off the stack + +*/ + +//Recursion - The act of a function calling itself +//Recursion IS NOT ITERATION +//Recursion is typically used to solve problems that we don't have certain +//guarantees on +//Recursion is OFTEN for nested stuff if we don't know HOW nested it will be + +//Ex: flatten an array with any number of nested arrays inside of it + + +//RECURSION IS MADE OF TWO PARTS: +//1. Recursive case - resumes recursion +//2. Base case - ends recursion + +// function countDown(num) { +// console.log(num); +// countDown(num - 1) +// } + +// countDown(10) \ No newline at end of file diff --git a/05-week/2-day/scratch.js b/05-week/2-day/scratch.js index e69de29..690ecf0 100644 --- a/05-week/2-day/scratch.js +++ b/05-week/2-day/scratch.js @@ -0,0 +1,37 @@ +//Stack data structure +// first in, last out + +//Commonly in JS we use arrays (push and pop) to emulate stacks + + +//CALL STACK - structure (based on a stack) that keeps track of function calls +// what is the order of operations? +//The call stack ONLY keeps track of function CALLS + +//A function is pushed to the call stack when its called +//A function is popped off the call stack when it returns + +//The function that is currently being executed is ALWAYS the function at the very top +// of the call stack +//ALL FUNCTIONS BELOW THE ONE ON THE TOP is paused + +//Recursion - The act of a function calling itself +//its very similar iteration (looping) but its not iteration + +//Nested russian doll OR taking a big problem and making smaller and smaller and smaller + +/* + +//Three important parts of recursive functions (YOU MUST HAVE AT LEAST 2/3 (base case must be implied)) +1. Recursive case - In what condition do we recurse? + +2. Recursive STEP - Manipulating something so you eventually hit the base case + +3. Base case - in what condition do we stop recursion? +*/ + +//Inifinite recursion is possible, so have a base case + +//When you are using recursion to build something (array, string, etc) +//1. You have to build it backwards +//2. Typically (almost always) you will use the return statements to build that thing \ No newline at end of file From 87e6512609a2e25f9f18cef55ae66a25208d2084 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CAlexi?= <“alexi56”@comcast.net> Date: Tue, 23 Jul 2024 20:02:06 -0600 Subject: [PATCH 25/26] pt 2 --- 05-week/2-day/scratch.js | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/05-week/2-day/scratch.js b/05-week/2-day/scratch.js index 690ecf0..b2af7c0 100644 --- a/05-week/2-day/scratch.js +++ b/05-week/2-day/scratch.js @@ -34,4 +34,20 @@ //When you are using recursion to build something (array, string, etc) //1. You have to build it backwards -//2. Typically (almost always) you will use the return statements to build that thing \ No newline at end of file +//2. Typically (almost always) you will use the return statements to build that thing + +function reverseName(name) { + let nameArr = name.split(''); + let lastLetter = nameArr.pop(); + + console.log(lastLetter) + + if (nameArr.length) { + let string = nameArr.join(''); + reverseName(string); + } + + return; + } + + reverseName("marlon") \ No newline at end of file From 88f038b6ac95b4e81f49059de0021fcd5ba5bb2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CAlexi?= <“alexi56”@comcast.net> Date: Fri, 26 Jul 2024 17:55:33 -0600 Subject: [PATCH 26/26] Week 5 Day 3 --- 05-week/3-day/scratch.js | 106 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 106 insertions(+) diff --git a/05-week/3-day/scratch.js b/05-week/3-day/scratch.js index e69de29..31bd403 100644 --- a/05-week/3-day/scratch.js +++ b/05-week/3-day/scratch.js @@ -0,0 +1,106 @@ +//Default parameters +//You can specify a default value for a parameter, and if you don't pass +//a value in for that param, JS will use the default value otherwise it'll +//use the value passed in + + +// function sayHello(friend = "friend") { //friend will choose bro'lady if no value is passed in +// console.log(`Hey ${friend}, how are ya?`); + +// console.log(`Hey ${friend}, how are ya?`); +// console.log(`Hey ${friend}, how are ya?`); +// console.log(`Hey ${friend}, how are ya?`); +// } + +// sayHello(); + +// sayHello("Ratguy"); + +// if (true) { +// let fruit = "lobster" + + +// console.log(fruit); +// } +function recursiveSum(num) { + if (num === 1) { + return 1; + } + + return num + recursiveSum(num - 1) + } + console.log(recursiveSum(5)) +/*********************************************************************** +Write a recursive function called `sumArray` that takes an array of integers +and returns the value of all the integers added together. Your array may +include a mix of positive and negative integers! + +Examples: + +sumArray([1, 2, 3]); // 6 +sumArray([0, 1, -3]); // -2 +sumArray([1, 2, 3, 4, 5]); // 15 +***********************************************************************/ + +// function sumArray(arr) { +// // Your code here +// if (arr.length === 0) { +// return 0; +// } + +// let firstItem = arr.shift(); +// return firstItem + sumArray(arr); +// } + +// sumArray([5]) // 5 + +// console.log(sumArray([1, 2])) // 6 +// console.log(sumArray([0, 1, -3])); // -2 +// console.log(sumArray([1, 2, 3, 4, 5])); // 15 + +// function sumArray(arr) { +// let lastNum = arr.pop(); // +// let total = lastNum; +// if(arr.length) { +// total += sumArray(arr); +// } +// return total; +// } + + +/*********************************************************************** +Write a recursive function called `addToTwelve` that will return true if there +are two adjacent numbers in the input array that can sum up to 12. Otherwise, +return false. + +Examples: + +addToTwelve([1, 3, 4, 7, 5]); // true +addToTwelve([1, 3, 4, 7, 6]); // false +addToTwelve([1, 11, 4, 7, 6]); // true +addToTwelve([1, 12, 4, 7, 6]); // false +addToTwelve([1]); // false +***********************************************************************/ + + +// function addToTwelve(arr) { +// // Your code here +// if (arr.length < 2) return false; +// if (arr[0] + arr[1] === 12) return true; + +// return addToTwelve(arr.slice(1)); +// } + +function addToTwelve(arr) { + if (arr.length < 2) return false; + if (arr[arr.length - 1] + arr[arr.length - 2] === 12) return true; + + arr.pop(); + return addToTwelve(arr); +} + +console.log(addToTwelve([1, 3, 4, 7, 5])); // true +console.log(addToTwelve([1, 3, 4, 7, 6])); // false +console.log(addToTwelve([1, 11, 4, 7, 6])); // true +console.log(addToTwelve([1, 12, 4, 7, 6])); // false +console.log(addToTwelve([1])); // false