Skip to content

Commit cdee807

Browse files
committed
Debugging (ex. 1 to 12)
+ Finished Debugging module
1 parent 84d7e97 commit cdee807

14 files changed

+293
-13
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/*
2+
Use the JavaScript Console to Check the Value of a Variable:
3+
Use the console.log() method to print the value of the variable a where noted in the code.
4+
5+
- Your code should use console.log() to check the value of the variable a.
6+
*/
7+
let a = 5;
8+
let b = 1;
9+
a++;
10+
// Only changed code below this line
11+
console.log(a);
12+
let sumAB = a + b;
13+
console.log(sumAB);
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/*
2+
Understanding the Differences between the freeCodeCamp and Browser Console:
3+
First, open your browser console so you can see the logs.
4+
To do that, you can right-click the freeCodeCamp navigation bar at the top and click inspect on most browsers.
5+
Then find the console tab in the window that opens.
6+
7+
After that, use console.log to log the output variable.
8+
View the two consoles to see the log. Finally, use console.clear after your log to clear the browser console.
9+
View the difference in the two consoles.
10+
11+
- You should use console.log() to print the output variable.
12+
- You should use console.clear() to clear the browser console.
13+
- You should clear the console after your log.
14+
*/
15+
let output = "Get this to show once in the freeCodeCamp console and not at all in the browser console";
16+
console.log(output);
17+
console.clear();
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/*
2+
Use typeof to Check the Type of a Variable:
3+
Add two console.log() statements to check the typeof each of the two variables seven and three in the code.
4+
5+
- Your code should use typeof in two console.log() statements to check the type of the variables.
6+
- Your code should use typeof to check the type of the variable seven.
7+
- Your code should use typeof to check the type of the variable three.
8+
*/
9+
let seven = 7;
10+
let three = "3";
11+
console.log(seven + three);
12+
// Only changed code below this line
13+
console.log(typeof seven);
14+
console.log(typeof three);
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
Catch Misspelled Variable and Function Names:
3+
Fix the two spelling errors in the code so the netWorkingCapital calculation works.
4+
5+
- Check the spelling of the two variables used in the netWorkingCapital calculation, the console output should show that "Net working capital is: 2".
6+
- There should be no instances of mis-spelled variables in the code.
7+
- The receivables variable should be declared and used properly in the code.
8+
- There should be no instances of mis-spelled variables in the code.
9+
- The payables variable should be declared and used properly in the code.
10+
11+
Initial code:
12+
let receivables = 10;
13+
let payables = 8;
14+
let netWorkingCapital = recievables - payable;
15+
console.log(`Net working capital is: ${netWorkingCapital}`);
16+
*/
17+
let receivables = 10;
18+
let payables = 8;
19+
let netWorkingCapital = receivables - payables;
20+
console.log(`Net working capital is: ${netWorkingCapital}`);
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/*
2+
Catch Unclosed Parentheses, Brackets, Braces and Quotes:
3+
Fix the two pair errors in the code.
4+
5+
- Your code should fix the missing piece of the array.
6+
- Your code should fix the missing piece of the .reduce() method. The console output should show that Sum of array values is: 6.
7+
8+
Initial code:
9+
let myArray = [1, 2, 3;
10+
let arraySum = myArray.reduce((previous, current => previous + current);
11+
console.log(`Sum of array values is: ${arraySum}`);
12+
*/
13+
let myArray = [1, 2, 3];
14+
let arraySum = myArray.reduce((previous, current) => previous + current);
15+
console.log(`Sum of array values is: ${arraySum}`);
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/*
2+
Catch Mixed Usage of Single and Double Quotes:
3+
Fix the string so it either uses different quotes for the href value, or escape the existing ones.
4+
Keep the double quote marks around the entire string.
5+
6+
- Your code should fix the quotes around the href value #Home by either changing or escaping them.
7+
- Your code should keep the double quotes around the entire string.
8+
9+
Initial code:
10+
let innerHtml = "<p>Click here to <a href="#Home">return home</a></p>";
11+
console.log(innerHtml);
12+
*/
13+
let innerHtml = "<p>Click here to <a href=\"#Home\">return home</a></p>";
14+
console.log(innerHtml);
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
Catch Use of Assignment Operator Instead of Equality Operator:
3+
Fix the condition so the program runs the right branch, and the appropriate value is assigned to result.
4+
5+
- Your code should fix the condition so it checks for equality, instead of using assignment.
6+
- The condition should use either == or === to test for equality.
7+
8+
Initial code:
9+
let x = 7;
10+
let y = 9;
11+
let result = "to come";
12+
13+
if(x = y) {
14+
result = "Equal!";
15+
} else {
16+
result = "Not equal!";
17+
}
18+
19+
console.log(result);
20+
*/
21+
let x = 7;
22+
let y = 9;
23+
let result = "to come";
24+
25+
if(x === y) {
26+
result = "Equal!";
27+
} else {
28+
result = "Not equal!";
29+
}
30+
31+
console.log(result);
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
Catch Missing Open and Closing Parenthesis After a Function Call:
3+
Fix the code so the variable result is set to the value returned from calling the function getNine.
4+
5+
- Your code should fix the variable result, so it is set to the number that the function getNine returns.
6+
- Your code should call the getNine function.
7+
8+
Initial code:
9+
function getNine() {
10+
let x = 6;
11+
let y = 3;
12+
return x + y;
13+
}
14+
15+
let result = getNine;
16+
console.log(result);
17+
*/
18+
function getNine() {
19+
let x = 6;
20+
let y = 3;
21+
return x + y;
22+
}
23+
24+
let result = getNine();
25+
console.log(result);
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
Catch Arguments Passed in the Wrong Order When Calling a Function:
3+
The function raiseToPower raises a base to an exponent.
4+
Unfortunately, it's not called properly - fix the code so the value of power is the expected 8.
5+
6+
- Your code should fix the variable power, so it equals 2 raised to the 3rd power, not 3 raised to the 2nd power.
7+
- Your code should use the correct order of the arguments for the raiseToPower function call.
8+
9+
Initial code:
10+
function raiseToPower(b, e) {
11+
return Math.pow(b, e);
12+
}
13+
14+
let base = 2;
15+
let exp = 3;
16+
let power = raiseToPower(exp, base);
17+
console.log(power);
18+
*/
19+
function raiseToPower(b, e) {
20+
return Math.pow(b, e);
21+
}
22+
23+
let base = 2;
24+
let exp = 3;
25+
let power = raiseToPower(base, exp);
26+
console.log(power);
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
Catch Off By One Errors When Using Indexing:
3+
Fix the two indexing errors in the following function so all the numbers 1 through 5 are printed to the console.
4+
5+
- Your code should set the initial condition of the loop, so it starts at the first index.
6+
- Your code should fix the initial condition of the loop, so that the index starts at 0.
7+
- Your code should set the terminal condition of the loop, so it stops at the last index.
8+
- Your code should fix the terminal condition of the loop, so that it stops at 1 before the length.
9+
10+
Initial code:
11+
function countToFive() {
12+
let firstFive = "12345";
13+
let len = firstFive.length;
14+
// Only change code below this line
15+
for (let i = 1; i <= len; i++) {
16+
// Only change code above this line
17+
console.log(firstFive[i]);
18+
}
19+
}
20+
21+
countToFive();
22+
*/
23+
function countToFive() {
24+
let firstFive = "12345";
25+
let len = firstFive.length;
26+
// Only changed code below this line
27+
for (let i = 0; i < len; i++) {
28+
// Only changed code above this line
29+
console.log(firstFive[i]);
30+
}
31+
}
32+
33+
countToFive();

0 commit comments

Comments
 (0)