Skip to content

Commit a696e17

Browse files
committed
in this code the function is not working properly. I explained the issue and fixed the code.
1 parent eb5e0dc commit a696e17

File tree

1 file changed

+12
-4
lines changed
  • Sprint-2/2-mandatory-debug

1 file changed

+12
-4
lines changed

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

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

33
// Predict the output of the following code:
4-
// =============> Write your prediction here
4+
// =============> Write your prediction here: the function const should write inside the call function.//
55

66
const num = 103;
77

@@ -14,11 +14,19 @@ 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+
// =============> write the output here: The output is 3 for all three calls.
1818
// Explain why the output is the way it is
19-
// =============> write your explanation here
19+
// =============> write your explanation here: The function getLastDigit is not taking any parameters, so it always uses the outer variable num, which is 103. That's why the output is always 3.
2020
// Finally, correct the code to fix the problem
21-
// =============> write your new code here
21+
// =============> write your new code here:
22+
23+
/*function getLastDigit(num) {
24+
return num.toString().slice(-1);
25+
}
26+
27+
console.log(`The last digit of 42 is ${getLastDigit(42)}`);
28+
console.log(`The last digit of 105 is ${getLastDigit(105)}`);
29+
console.log(`The last digit of 806 is ${getLastDigit(806)}`); */
2230

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

0 commit comments

Comments
 (0)