Skip to content

Commit 91d2061

Browse files
committed
Work on 2-mandatory-debug
1 parent 104e2ea commit 91d2061

3 files changed

Lines changed: 15 additions & 9 deletions

File tree

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

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

33
// =============> write your prediction here
4+
// I think the function will not work because nothing is returned
45

56
function multiply(a, b) {
6-
console.log(a * b);
7+
return a * b;
78
}
89

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

1112
// =============> write your explanation here
13+
// I was almost correct but I had to also remove the console.log()
1214

1315
// Finally, correct the code to fix the problem
1416
// =============> write your new code here
17+
// 10: return a * b;

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
// Predict and explain first...
22
// =============> write your prediction here
3+
// It won't run because there's a semicolon straight after return
34

45
function sum(a, b) {
5-
return;
6-
a + b;
6+
return a + b;
77
}
88

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

1111
// =============> write your explanation here
1212
// Finally, correct the code to fix the problem
1313
// =============> write your new code here
14+
// remove the semicolon

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
// Predict the output of the following code:
44
// =============> Write your prediction here
5+
// I think it wont run because there's nothing passed into the function
6+
// also it is using the value of num outside of the function wich isn't correct
57

6-
const num = 103;
7-
8-
function getLastDigit() {
8+
function getLastDigit(num) {
99
return num.toString().slice(-1);
1010
}
1111

@@ -14,11 +14,13 @@ console.log(`The last digit of 105 is ${getLastDigit(105)}`);
1414
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+
// =============> it just returned 3
18+
1819
// Explain why the output is the way it is
19-
// =============> write your explanation here
20+
// =============> Because value is mistakenly defined outside of the function
21+
2022
// Finally, correct the code to fix the problem
21-
// =============> write your new code here
23+
// =============> pass num into the function and remove the constant 103 outside
2224

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

0 commit comments

Comments
 (0)