Skip to content

Commit 95e7076

Browse files
committed
completed 2-madatory-debug
1 parent bd4fe1f commit 95e7076

File tree

3 files changed

+31
-3
lines changed

3 files changed

+31
-3
lines changed

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

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

33
// =============> write your prediction here
4-
4+
// the function will not return anything.
55
function multiply(a, b) {
66
console.log(a * b);
77
}
@@ -10,5 +10,13 @@ console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`);
1010

1111
// =============> write your explanation here
1212

13+
// declared a variable called result and stored a*b.
14+
1315
// Finally, correct the code to fix the problem
1416
// =============> write your new code here
17+
function multiply(a, b) {
18+
console.log(a * b);
19+
const result = a*b;
20+
return result;
21+
}
22+
console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`);

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
11
// Predict and explain first...
22
// =============> write your prediction here
3-
3+
// This appears correct. The function has been defined and called sum, a is 10 and b is 32 so we should get 42.
44
function sum(a, b) {
55
return;
6-
a + b;
6+
a + b;
77
}
88

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

1111
// =============> write your explanation here
12+
// The sum of 10 and 32 is undefined. On line five the function has been exited because of the ; this because the function doesn't return anything.
1213
// Finally, correct the code to fix the problem
1314
// =============> write your new code here
15+
16+
function sum(a, b) {
17+
return a + b;
18+
}
19+
20+
console.log(`The sum of 10 and 32 is ${sum(10, 32)}`);

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// Predict the output of the following code:
44
// =============> Write your prediction here
55

6+
// It will return three as a string.
67
const num = 103;
78

89
function getLastDigit() {
@@ -15,10 +16,22 @@ console.log(`The last digit of 806 is ${getLastDigit(806)}`);
1516

1617
// Now run the code and compare the output to your prediction
1718
// =============> write the output here
19+
// "3"
20+
1821
// Explain why the output is the way it is
1922
// =============> write your explanation here
23+
// This is because they've defined num as 103, and they've used num inside the function, last digit of 103 is 3.
2024
// Finally, correct the code to fix the problem
2125
// =============> write your new code here
2226

27+
function getLastDigit(aNumber) {
28+
return aNumber.toString().slice(-1);
29+
}
30+
31+
console.log(`The last digit of 42 is ${getLastDigit(42)}`);
32+
console.log(`The last digit of 105 is ${getLastDigit(105)}`);
33+
console.log(`The last digit of 806 is ${getLastDigit(806)}`);
34+
2335
// This program should tell the user the last digit of each number.
2436
// Explain why getLastDigit is not working properly - correct the problem
37+
// This is because they've defined num as 103 so the result will always be 3. The arguments should be used instead (42, 105, and 806) and num should not be used.

0 commit comments

Comments
 (0)