Skip to content

Commit 97592ac

Browse files
committed
2.js updated
1 parent 468a49f commit 97592ac

File tree

1 file changed

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

1 file changed

+12
-0
lines changed

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

Lines changed: 12 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+
// I guess line 7 should have written after line 11. and the num should have been a parameter.
56

67
const num = 103;
78

@@ -15,10 +16,21 @@ 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
1822
// Explain why the output is the way it is
23+
//every call returned "3" (the last digit of 103) instead of the number I pass because the const num was unnecessary if we wanted the function to work for any call.
1924
// =============> write your explanation here
2025
// Finally, correct the code to fix the problem
2126
// =============> write your new code here
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)}`);
2234

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

0 commit comments

Comments
 (0)