forked from leafoflegend/2001-CPU
-
Notifications
You must be signed in to change notification settings - Fork 0
/
js-intro.js
122 lines (99 loc) · 2.67 KB
/
js-intro.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
// - Variables
// - `let` vs `const`
// Demo let vs const
// reassigning variables
var myVar = 'this is confusing!';
let myLet = 'let something be this';
const myConst = 'let this never change';
let myNum = 0;
myNum = myNum + 1;
console.log(myNum);
myNum = 'Preston';
console.log(myNum);
let myName = 'Preston';
myName = myName + ' Wallace';
console.log(myName);
let newDoubleQuote = "my cat is fun";
console.log(newDoubleQuote);
let myNumString = '8';
let myNum2 = 8;
console.log(myNumString);
console.log(myNum2);
// - Data Types
// - `string`
// - `array`
// - `number`
// String types, adding to strings
// Number types & operators (+, -, *, /)
// Array types
// Reassigning strings to numbers and vice versa
// Defining an array
// Arrays are zero indexed
// Accessing an element of an array
let aNewNum = 7;
console.log(typeof aNewNum);
// console.log(typeof typeof aNewNum);
// aNewNum = '8';
// console.log(typeof aNewNum);
// A few ways to increment
aNewNum = aNewNum + 1;
console.log(aNewNum);
aNewNum += 1;
aNewNum++;
console.log(aNewNum);
aNewNum = aNewNum * 5;
console.log(aNewNum);
aNewNum /= 10;
console.log(aNewNum);
aNewNum--;
console.log(aNewNum);
// Arrays
let newArr = [8, 9, 10, 'Brian', 'Sam', 2];
console.log(newArr);
console.log(newArr[0]);
console.log(newArr[2]);
console.log(newArr[4]);
newArr[6] = 'dog';
console.log(newArr[6]);
console.log(newArr);
console.log(Array.isArray(newArr));
// - Loops
// - `for` loop
// Looping over an array
// Three different parts of a for...let/const loop
// Accessing an element within an iteration
// What is the index?
// What is the value/element?
const myNums = [1, 2, 3, 4, 5];
for(let i = 0; i < myNums.length ; i++) {
// console.log(i);
let myElem = myNums[i];
myElem += 1;
console.log(myElem);
}
const myDogs = ['Yoda', 'Buck', 'Fido', 'Barkley', 'Koya'];
for(let i = 0; i < myDogs.length ; i++) {
// console.log(i);
let myElem = myDogs[i];
myElem = myElem + ' says "bark"';
console.log(myElem);
}
const myCats = [2, 5, 3, 56, 23, 'Yoda', 'Buck', 'Fido', 'Barkley', 'Koya'];
console.log('myCats array length is ', myCats.length)
console.log('the last element of this array is', myCats[myCats.length - 1])
for(let i = 0; i < myCats.length ; i++) {
let myElem = myCats[i];
myElem = myElem + ' says "meow"';
// console.log(myElem);
}
/*
< ---------------------- IF WE HAVE TIME ---------------------- >
*/
// - Conditionals
// - `if` and `else`
// - Functions
// - simple `function`
// < ---------------------- jQuery, IF WE HAVE MORE TIME ---------------------- >
// $('h1').css('background-color', 'yellow')
// const paragraphs = $('p');
// $('main').append($('<p>').text('hello in a p tag'))