#100Devs - Javascript Arrays (cohort 2)

This is class 19 for our Free Web Dev Bootcamp for folx affected by the pandemic. Join live T/Th 6:30pm ET leonnoel.com/twitch and ask questions here: leonnoel.com/discord

Skip to first slide
Slide 1 of 54

 

Javascript - Arrays

#100Devs

Leon Noel

Metal Fist terrorists claim responsibility
Broken household name usually said in hostility
Um... what is MF? You silly


Slide 2 of 54

Agenda


Slide 3 of 54

Questions

About last class or life


Slide 4 of 54

Checking In

Like and Retweet the Tweet

!checkin


Slide 5 of 54

Want to be fancy?

Best Clip Get's Special Color On Discord!


Slide 6 of 54

Submitting Work

I WANT IT

Homework: https://forms.gle/PLuuSi7aHeL7wbMQ9

 


Slide 7 of 54

Networking

3 Individuals Already In Tech

2 Coffee Chats


Slide 8 of 54

USE THE SHEET!

Networking Google Sheet


Slide 9 of 54

Coding Challenges

Daily

Codewars 8kyu Fundamentals


Slide 10 of 54

Paid Client

Due by Mar. 31st


Slide 11 of 54

TURN IT UP!


Slide 12 of 54

Programming


Slide 13 of 54

A computer will do what you tell it to do.


Slide 14 of 54

What is a program?

A program is a set of instructions that you write to tell a computer what to do


Slide 15 of 54

What is a programming?

Programming is the task of writing those instructions in a language that the computer can understand.


Slide 16 of 54

JAVASCRIPT


Slide 17 of 54

Has a specific 'Syntax'

Syntax: "Spelling and grammar" rules of a programming language.


Slide 18 of 54

Variables

Declaration: let age

 

Assignment: age = 25

 

Both at the same time:

let age = 25


Slide 19 of 54

Conditional Syntax

if(condition is true) {
  //Do this cool stuff
}else if(condition is true){
  //Do this other cool stuff
}else{
  //Default cool stuff
}

Slide 20 of 54

🚨 DANGER 🚨

Assignment vs. Comparison


Slide 21 of 54

Multiple Conditions

if (name === "Leon" && status === "Ballin"){
 //Wink at camera
}

Slide 22 of 54

Multiple Conditions

if (day === "Saturday" || day === "Sunday"){
  //It is the weekend
}

Slide 23 of 54

Functions

What are functions?


Slide 24 of 54

Functions


Slide 25 of 54

Functions

function name(parameters){
  //body
}

//call
name(arguments)

Slide 26 of 54

Functions

function yell(word){
  alert(word)
}


yell("HELLO")

Slide 27 of 54

Loops

What are loops?


Slide 28 of 54

Loops


Slide 29 of 54

Loops - For

for (let i = 1; i < 5; i++) {
  console.log(i)
}

Slide 30 of 54

Loops - While

let count = 0 

while(count < 5){
  console.log(count)
  count++
}

Slide 31 of 54

Let's Code

Bring It On - All Or Nothing!


Slide 32 of 54

Arrays

What are arrays?


Slide 33 of 54

Toasters


Slide 34 of 54

Arrays


Slide 35 of 54

Declaring Arrays

let newArr = new Array()

Array Constructor


Slide 36 of 54

Declaring Arrays

let newArr = []

Literal Notation


Slide 37 of 54

Declaring Arrays

newArr = ['Zebra',true,21]

Arrays are populated with elements

Elements can be of any type


Slide 38 of 54

Declaring Arrays

🚨Empty spaces leave an empty element 🚨


Slide 39 of 54

Array Indexing


Slide 40 of 54

Array Indexing

newArr = ['Zebra',,true,21]

console.log( newArr[0] )  //Zebra
console.log( newArr[1] )  //undefined
console.log( newArr[2] )  //true
console.log( newArr[3] )  //21

Elements can be accessed by their index numbers


Slide 41 of 54

Array Indexing

newArr = ['Zebra',,true,21]

newArr[1] = 'Bob'

console.log( newArr )  

// ['Zebra','Bob',true,21]

Elements can be updated by using the index at that position


Slide 42 of 54

Array Indexing

let cars = ['Honda', 'Toyota', 'Ford', 'Tesla']
let nums = [1,2,3]
cars = nums
console.log( cars ) //[1,2,3]

You can overwrite whole arrays by assigning an array to a different array


Slide 43 of 54

Array Length

console.log( newArr.length ) //4

How do you determine how many elements are in your array?


Slide 44 of 54

Let's Code

Array Dat - In It To Win It


Slide 45 of 54

Array Iteration

let bestColors = ['green','blue','yellow','black']

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

Iterates through an array passing in the value and index of each element 


Slide 46 of 54

Array Iteration

let bestColors = ['green','blue','yellow','black']

bestColors.forEach((x,i)=> console.log(x))

Iterates through an array passing in the value and index of each element 


Slide 47 of 54

Let's Code

Array Dat - Fight To The Finish


Slide 48 of 54

Other Arrays Methods

let bestRappers2020 = ['6ix9ine','Polo G','6ix9ine']

let removed = bestRappers2020.shift()

console.log( bestRappers2020 ) // ['Polo G', '6ix9ine']

Remove item from the beginning of an Array


Slide 49 of 54

Other Arrays Methods

let bestRappers2020 = ['Polo G','6ix9ine']

let removedAgain = bestRappers2020.pop()

console.log( bestRappers2020 ) // ['Polo G']

Remove item from the end of an Array


Slide 50 of 54

Other Arrays Methods

let bestRappers2020 = ['Polo G']

let removed = bestRappers2020.unshift('Dylan')

console.log( bestRappers2020 ) // ['Dylan','Polo G']

Add item to the beginning of an Array


Slide 51 of 54

Other Arrays Methods

let bestRappers2020 = ['Dylan','Polo G']

let removed = bestRappers2020.push('Dylan')

console.log( bestRappers2020 ) // ['Dylan','Polo G','Dylan']

Add item to the end of an Array


Slide 52 of 54

Other Arrays Methods

let bestRappers2020 = ['Dylan','Polo G','Dylan']

let bestRappersAllTime = bestRappers2020.map(x => 'Dylan')

bestRappersAllTime.unshift('Dylan')
  
bestRappersAllTime.push('Dylan')

console.log( bestRappersAllTime ) 

// ['Dylan','Dylan','Dylan', 'Dylan', 'Dylan']

Slide 53 of 54

Let's Code

Array Dat - Worldwide Cheersmack


Slide 54 of 54

Homework

Read: JSWay Arrays
Read: https://javascript.info/array-methods
Read: JSWay Objects
Read: https://eloquentjavascript.net/04_data.html
Do: Minimum of 1 https://codewars.com 8 Kyu Fundamentals Track EVERY DAY - 20 mins then look at solution!
Do: https://javascript30.com Day 04 Array Cardio (super hard, do it on Discord together)