Skip to content

Commit fb0d426

Browse files
committed
2.2
1 parent d473199 commit fb0d426

File tree

4 files changed

+26
-17
lines changed

4 files changed

+26
-17
lines changed

Sprint-2/1-key-errors/2.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33

44
// this function should square any number but instead we're going to get an error
55

6-
// =============> write your prediction of the error here
6+
// =============> write your prediction of the error here: There will be an error because we put a value (3) as a function's parameter instead of using variable names. We also don't know where num comes from as we have't defined/ declared that.
77

88
// function square(3) {
99
// return num * num;
1010
// }
1111

12-
// =============> write the error message here
12+
// =============> write the error message here: SyntaxError: Unexpected number
1313

14-
// =============> explain this error message here
14+
// =============> explain this error message here: We get an error message saying that there is an unexpected number on line 8 (Syntax Error).
1515

1616
// Finally, correct the code to fix the problem
1717

Sprint-2/2-mandatory-debug/0.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
// Predict and explain first...
22

3-
// =============> write your prediction here
3+
// =============> write your prediction here: There is no return value value for the function multiply. Though it print the value of a * b in the function, this function cannot be called outside of the function (on line 9). So, it will be undefinded. WE need a return
44

55
// function multiply(a, b) {
66
// console.log(a * b);
77
// }
88

99
// console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`);
1010

11-
// =============> write your explanation here
11+
// =============> write your explanation here: We need to change console.log on line 6 to return so that we can call in outside of the function.
1212

1313
// Finally, correct the code to fix the problem
1414
// =============> write your new code here

Sprint-2/2-mandatory-debug/1.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Predict and explain first...
2-
// =============> write your prediction here
2+
// =============> write your prediction here: There is a semi column on line 5 after the return which separates it from line 6. We don't know what we are returning.
33

44
// function sum(a, b) {
55
// return;
@@ -8,7 +8,7 @@
88

99
// console.log(`The sum of 10 and 32 is ${sum(10, 32)}`);
1010

11-
// =============> write your explanation here
11+
// =============> write your explanation here: SInce we don't know what we are returning, we will get an undefined value for the function.
1212
// Finally, correct the code to fix the problem
1313
// =============> write your new code here
1414
function sum(a, b) {

Sprint-2/2-mandatory-debug/2.js

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,33 @@
11
// Predict and explain first...
22

33
// Predict the output of the following code:
4-
// =============> Write your prediction here
4+
// =============> Write your prediction here: We are trying to convert the last figure (last index) of a number to a String. We will surely get "2", "5" and "6"
55

6-
const num = 103;
6+
// const num = 103;
77

8-
function getLastDigit() {
9-
return num.toString().slice(-1);
10-
}
8+
// function getLastDigit() {
9+
// return num.toString().slice(-1);
10+
// }
1111

12-
console.log(`The last digit of 42 is ${getLastDigit(42)}`);
13-
console.log(`The last digit of 105 is ${getLastDigit(105)}`);
14-
console.log(`The last digit of 806 is ${getLastDigit(806)}`);
12+
// console.log(`The last digit of 42 is ${getLastDigit(42)}`);
13+
// console.log(`The last digit of 105 is ${getLastDigit(105)}`);
14+
// console.log(`The last digit of 806 is ${getLastDigit(806)}`);
1515

1616
// Now run the code and compare the output to your prediction
17-
// =============> write the output here
17+
// =============> write the output here: After running our code, we saw that it printed "3" all over. Which comes from our initial declaration of num = 103
1818
// Explain why the output is the way it is
19-
// =============> write your explanation here
19+
// =============> write your explanation here: We have declared num as a const which makes it unchangeable through out. We cannot redeclare it. The second thing is that we will need to add num inside of the parameter of the function.
2020
// Finally, correct the code to fix the problem
2121
// =============> write your new code here
22+
let num = 103;
23+
24+
function getLastDigit(num) {
25+
return num.toString().slice(-1);
26+
}
27+
28+
console.log(`The last digit of 42 is ${getLastDigit(42)}`);
29+
console.log(`The last digit of 105 is ${getLastDigit(105)}`);
30+
console.log(`The last digit of 806 is ${getLastDigit(806)}`);
2231

2332
// This program should tell the user the last digit of each number.
2433
// Explain why getLastDigit is not working properly - correct the problem

0 commit comments

Comments
 (0)