Skip to content

Commit f6e36a3

Browse files
Matthew HolmesMatthew Holmes
authored andcommitted
adding js lectures
1 parent 614c440 commit f6e36a3

File tree

7 files changed

+638
-0
lines changed

7 files changed

+638
-0
lines changed
Lines changed: 230 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,230 @@
1+
// alert('hello world')
2+
3+
// similar to python print()
4+
5+
// console.log('hello Class')
6+
// console.warn('something is up')
7+
// console.info('Page Loaded')
8+
9+
// let userInput = prompt('how is your day?')
10+
// alert(userInput)
11+
12+
let color= 'yellow'
13+
// yellow in terminal
14+
console.log(color)
15+
color = 'red'
16+
// red in console
17+
console.log(color)
18+
19+
const favColor = 'blue'
20+
// blue fave color in console
21+
console.log(favColor, 'fav color')
22+
// favColor = 'pink'
23+
24+
// you cant change variable using const
25+
const socialSecNum= 123456
26+
// can change the variable set using let
27+
let lastName= 'Smith'
28+
29+
// console.log(typeof color)
30+
31+
// let numberOne= 1
32+
// console.log(typeof 1)
33+
34+
// --------------------------------------------------------------------------------------------------------
35+
36+
//Data Types
37+
'hello World' // String
38+
"hello World" // String
39+
4 // Number
40+
4.7 // Number
41+
true // Boolean
42+
[1,2,3] // Array
43+
{name:'Tom'} // Object (Js) --> dict (py)
44+
undefined // undefined (value does not exist)
45+
null // intentional absence of value
46+
// ex: year == null
47+
48+
// let x = '24' + "Tomorrow"
49+
// console.log(x) // 24Tomorrow
50+
// console.log(typeof x) // string
51+
52+
53+
// Type coercion // javaScript converts 24 into a string
54+
55+
// let x = 24 + 'Tomorrow'
56+
// console.log(x) // 24Tomorrow
57+
58+
// javaScript ignores extra +
59+
// let x = 24 + + 6 + 'tomorrow'
60+
// console.log(x) //30tomorrow
61+
62+
let number = 5
63+
console.log(number == '5') //true // implicit relationship: javaScript auto converts '5' string to number 5
64+
console.log(number === '5') //false // explicit relationship: javaScrip is looking for an exact match
65+
66+
// ------------------------------------------------------------------------------------------------
67+
68+
// numbers in javaScript are all numbers
69+
let a= 1 // number (Js) --> integer (py)
70+
let b= 1.2 // number (Js) --> float (py)
71+
let c= 123e7 // larger number
72+
let d= 123e-7 // larger negative number
73+
74+
let num= 11
75+
if (num<10){
76+
console.log('number is less then 10')
77+
}
78+
else if(num>12){ // elif statement
79+
console.log('number is greater than 12')
80+
}
81+
else {
82+
console.log('number is between 10 - 12')
83+
}
84+
85+
// Objects----------------------------------------------------------------------------------------------
86+
87+
// objects
88+
// key:value
89+
let person = {
90+
firstName: 'Jackson',
91+
lastName: 'Brown',
92+
age: 30,
93+
pets:{
94+
dog: 'spot',
95+
cat: 'ginger',
96+
rock: 'rocky',
97+
}
98+
}
99+
100+
console.log(person)
101+
console.log(person['firstName'], 'square bracket "firstName"')
102+
console.log(person.lastName, 'person.lastName')
103+
104+
// update age
105+
person.age = 40
106+
console.log(person)
107+
console.log(person.age)
108+
109+
// // increment age using += 1
110+
// person.age += 1
111+
// console.log(person.age)
112+
113+
// increment age using ++ : increases age by 1
114+
// person.age ++
115+
// console.log(person.age)
116+
117+
console.log(person.pets)
118+
119+
let colors = {
120+
'red': '#ff0000',
121+
'green': '#00ff00',
122+
'blue': '#0000ff'
123+
}
124+
125+
for(key in colors){
126+
console.log(colors[key])
127+
}
128+
129+
console.log(Object.keys(colors))
130+
console.log(Object.values(colors))
131+
132+
for(const [key, value] of Object.entries(colors)){
133+
console.log(`${key}:${value}`) // (py) -->: f'{variable_name}'
134+
}
135+
136+
// Array-------------------------------------------------------------------------------------------------
137+
138+
// Array
139+
let pies = ['Apple','Pumpkin', 'Pecan', 'Sweet Potato']
140+
141+
// for of loop
142+
for(pie of pies){
143+
console.log(pie) // returns object at index position
144+
// console.log(`${pie}`)
145+
}
146+
147+
// for in loop 'in for index'
148+
for(pie in pies){
149+
console.log(pie) // returns index position of object
150+
}
151+
152+
// add item to array
153+
154+
// push()
155+
pies.push('Peach')
156+
pies.push('Blueberry')
157+
console.log(pies)
158+
159+
// remove item of array
160+
161+
// pop() removes last item of array
162+
let bestPie= pies.pop()
163+
console.log(bestPie) // returns Blueberry
164+
165+
166+
// include method
167+
168+
// if pies array contains Pumpkin
169+
if(pies.includes('Pumpkin')){
170+
console.log('it has pumpkin')
171+
}
172+
173+
// slice() makes a copy
174+
175+
// grab a copy starting at index 2 and ends at index 3
176+
i =pies.slice(2,3)
177+
console.log(i, 'checking slice')
178+
console.log(pies) // (5) ['Apple', 'Pumpkin', 'Pecan', 'Sweet Potato', 'Peach']
179+
180+
// splice() removes items
181+
182+
// starts at index 2 and removes 1 instance
183+
x = pies.splice(2,1)
184+
console.log(x,"checking splice") // ['Pecan'] 'checking splice'
185+
console.log(pies) // (4) ['Apple', 'Pumpkin', 'Sweet Potato', 'Peach']
186+
187+
// .join() joins the array and returns a string
188+
let stringPies= pies.join(',')
189+
// console.log(stringPies)
190+
191+
// console.log(pies) // (4) ['Apple', 'Pumpkin', 'Sweet Potato', 'Peach']
192+
193+
194+
// for(let i=0; i<100; i++){
195+
196+
// prints i in range 100
197+
// i ++ increases i by one 1 per loop
198+
for(i=0; i<100; i++){
199+
// console.log(i)
200+
}
201+
202+
// for(let i=0; i<pies.length; i++){
203+
// console.log(i,pies[i])
204+
// pies[i] = 'X'
205+
// console.log(pies)
206+
// }
207+
208+
// array method +
209+
// anonymous function(pie)
210+
pies.forEach(function(pie){
211+
console.log(pie) // returns object at each index similar to a for of loop
212+
})
213+
214+
215+
// Functions---------------------------------------------------------------------------------------------------
216+
217+
function sayHello(){
218+
let color = 'blue'
219+
return color
220+
}
221+
// console.log(sayHello()) // 'blue'
222+
223+
function addNums(x,y){
224+
return x+y
225+
}
226+
console.log(addNums(2,2,6))
227+
228+
const arrowFunct = (num1, num2) => {
229+
return num1 + num2
230+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
7+
<title>Intro</title>
8+
<!-- linking app.js -->
9+
<!-- defer scr="" loads page before javascript file -->
10+
<script defer src="app.js"></script>
11+
</head>
12+
<body>
13+
<h1>JavaScript Intro</h1>
14+
</body>
15+
</html>

0 commit comments

Comments
 (0)