Skip to content

Commit eab435e

Browse files
committed
fix(sprint-2): add missing parameter to getLastDigit function
1 parent ddcbe99 commit eab435e

File tree

1 file changed

+11
-0
lines changed
  • Sprint-2/2-mandatory-debug

1 file changed

+11
-0
lines changed

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
// Predict the output of the following code:
44
// =============> Write your prediction here
5+
// All outputs will be "3" because function has no parameter and always uses global num (103)
56

67
const num = 103;
78

@@ -15,10 +16,20 @@ 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+
// The last digit of 42 is 3
20+
// The last digit of 105 is 3
21+
// The last digit of 806 is 3
22+
1823
// Explain why the output is the way it is
1924
// =============> write your explanation here
25+
// Bug: Function has no parameter, so arguments (42, 105, 806) are ignored. Always uses global num (103)
26+
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/slice
27+
2028
// Finally, correct the code to fix the problem
2129
// =============> write your new code here
30+
function getLastDigit(number) {
31+
return number.toString().slice(-1);
32+
}
2233

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

0 commit comments

Comments
 (0)