Skip to content

Commit 8527416

Browse files
committed
Updated comments to clarify the behavior of getLastDigit function and corrected it to accept various inputs.
1 parent dc6c2ef commit 8527416

File tree

1 file changed

+10
-3
lines changed
  • Sprint-2/2-mandatory-debug

1 file changed

+10
-3
lines changed

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

Lines changed: 10 additions & 3 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+
// =============> num has already been declared as 103, therefore, no other number can be used.
55

66
const num = 103;
77

@@ -14,11 +14,18 @@ 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+
// =============> The last digit is always 3 because no other inputs are allowed.
1818
// Explain why the output is the way it is
19-
// =============> write your explanation here
19+
// =============> No other inputs are allowed as num will always be defined as 103.
2020
// Finally, correct the code to fix the problem
2121
// =============> write your new code here
22+
function getLastDigit(num) {
23+
return num.toString().slice(-1);
24+
}
25+
26+
console.log(`The last digit of 42 is ${getLastDigit(42)}`);
27+
console.log(`The last digit of 105 is ${getLastDigit(105)}`);
28+
console.log(`The last digit of 806 is ${getLastDigit(806)}`);
2229

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

0 commit comments

Comments
 (0)