Skip to content

Commit 7ea670b

Browse files
author
Payman IB
committed
Fix getLastDigit function to accept parameter and return correct last digit
1 parent a5bdca3 commit 7ea670b

File tree

1 file changed

+20
-8
lines changed
  • Sprint-2/2-mandatory-debug

1 file changed

+20
-8
lines changed

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

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,35 @@
22

33
// Predict the output of the following code:
44
// =============> Write your prediction here
5+
// the result will be 3 times
6+
// const num = 103;
57

6-
const num = 103;
8+
// function getLastDigit() {
9+
// return num.toString().slice(-1);
10+
// }
711

8-
function getLastDigit() {
9-
return num.toString().slice(-1);
10-
}
11-
12-
console.log(`The last digit of 42 is ${getLastDigit(42)}`);
13-
console.log(`The last digit of 105 is ${getLastDigit(105)}`);
14-
console.log(`The last digit of 806 is ${getLastDigit(806)}`);
12+
// console.log(`The last digit of 42 is ${getLastDigit(42)}`);
13+
// console.log(`The last digit of 105 is ${getLastDigit(105)}`);
14+
// console.log(`The last digit of 806 is ${getLastDigit(806)}`);
1515

1616
// Now run the code and compare the output to your prediction
1717
// =============> write the output here
18+
//The last digit of 42 is 3
19+
// The last digit of 105 is 3
20+
// The last digit of 806 is 3
1821
// Explain why the output is the way it is
1922
// =============> write your explanation here
23+
// because num is defined as 103 and not taking any input from the function parameter.
2024
// Finally, correct the code to fix the problem
2125
// =============> write your new code here
2226

27+
function getLastDigit(num) {
28+
return num.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)}`);
2334
// This program should tell the user the last digit of each number.
2435
// Explain why getLastDigit is not working properly - correct the problem
36+
// because num is defined as 103 and not taking any input from the function parameter.

0 commit comments

Comments
 (0)