Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alexi bettinger/june 2024 #3

Open
wants to merge 26 commits into
base: main
Choose a base branch
from
Binary file added .DS_Store
Binary file not shown.
Binary file added 01-week/.DS_Store
Binary file not shown.
189 changes: 189 additions & 0 deletions 01-week/1-day/scratch.js
Original file line number Diff line number Diff line change
@@ -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'))
72 changes: 72 additions & 0 deletions 01-week/2-day/scratch.js
Original file line number Diff line number Diff line change
@@ -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('-'))
19 changes: 19 additions & 0 deletions 01-week/4-day/scratch.js
Original file line number Diff line number Diff line change
@@ -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)
}
}

107 changes: 107 additions & 0 deletions 01-week/5-day/scratch.js
Original file line number Diff line number Diff line change
@@ -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();
Loading