-
Notifications
You must be signed in to change notification settings - Fork 0
/
FCC-js-tutorial-part-04.js
120 lines (97 loc) · 3.01 KB
/
FCC-js-tutorial-part-04.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
/*
TODO: *Debugging
*/
// !4.01: Use the JavaScript Console to Check the Value of a Variable
let a = 5;
let b = 1;
a++;
// Only change code below this line
console.log(a)
let sumAB = a + b;
console.log(sumAB);
// !4.02: Understanding the Differences between the freeCodeCamp and Browser Console
let output = "Get this to show once in the freeCodeCamp console and not at all in the browser console";
console.log(output)
console.clear()
// !4.03: Use typeof to Check the Type of a Variable
let seven = 7;
let three = "3";
console.log(seven + three);
// Only change code below this line
console.log(seven + three)
console.log(typeof (seven))
console.log(typeof (three))
// !4.04: Catch Misspelled Variable and Function Names
let receivables = 10;
let payables = 8;
let netWorkingCapital = receivables - payables;
console.log(`Net working capital is: ${netWorkingCapital}`);
// !4.05: Catch Unclosed Parentheses, Brackets, Braces and Quotes
let myArray = [1, 2, 3];
let arraySum = myArray.reduce((previous, current) => (previous + current));
console.log(`Sum of array values is: ${arraySum}`);
// !4.06: Catch Mixed Usage of Single and Double Quotes
let innerHtml = "<p>Click here to <a href='#Home'>return home</a></p>";
console.log(innerHtml);
// !4.07:Catch Use of Assignment Operator Instead of Equality Operator
let x = 7;
let y = 9;
let result = "to come";
if (x == y) {
result = "Equal!";
} else {
result = "Not equal!";
}
console.log(result);
// !4.08:Catch Missing Open and Closing Parenthesis After a Function Call
function getNine() {
let x = 6;
let y = 3;
return x + y;
}
let result = getNine();
console.log(result);
// !4.09: Catch Arguments Passed in the Wrong Order When Calling a Function
function raiseToPower(b, e) {
return Math.pow(b, e);
}
let base = 2;
let exp = 3;
let power = raiseToPower(base, exp);
console.log(power);
// !4.10:Catch Off By One Errors When Using Indexing
function countToFive() {
let firstFive = "12345";
let len = firstFive.length;
// Only change code below this line
for (let i = 0; i < len; i++) {
// Only change code above this line
console.log(firstFive[i]);
}
}
countToFive();
// !4.11:Use Caution When Reinitializing Variables Inside a Loop
function zeroArray(m, n) {
// Creates a 2-D array with m rows and n columns of zeroes
let newArray = [];
for (let i = 0; i < m; i++) {
// Adds the m-th row into newArray
let row = []; // call row inside of the first for loop
for (let j = 0; j < n; j++) {
// Pushes n zeroes into the current row to create the columns
row.push(0);
row.in // add this line after the row.push(0)
}
// Pushes the current row, which now has n zeroes in it, to the array
newArray.push(row);
}
return newArray;
}
let matrix = zeroArray(3, 2);
console.log(matrix);
// !4.12: Prevent Infinite Loops with a Valid Terminal Condition
function myFunc() {
for (let i = 1; i <= 4; i += 2) {
console.log("Still going!");
}
}