You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Sprint-2/2-mandatory-debug/2.js
+9-2Lines changed: 9 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -3,7 +3,7 @@
3
3
// Predict the output of the following code:
4
4
// =============> Write your prediction here
5
5
// I expect each of the calls to return the last digit of "num" which is "3" its defined as a constant and we are using that const in the return statement.
6
-
6
+
/*
7
7
const num = 103;
8
8
9
9
function getLastDigit() {
@@ -13,7 +13,7 @@ function getLastDigit() {
13
13
console.log(`The last digit of 42 is ${getLastDigit(42)}`);
14
14
console.log(`The last digit of 105 is ${getLastDigit(105)}`);
15
15
console.log(`The last digit of 806 is ${getLastDigit(806)}`);
16
-
16
+
*/
17
17
// Now run the code and compare the output to your prediction
18
18
// =============> write the output here
19
19
// Output:
@@ -27,6 +27,13 @@ console.log(`The last digit of 806 is ${getLastDigit(806)}`);
27
27
28
28
// Finally, correct the code to fix the problem
29
29
// =============> write your new code here
30
+
functiongetLastDigit(num){
31
+
returnnum.toString().slice(-1);
32
+
}
33
+
34
+
console.log(`The last digit of 42 is ${getLastDigit(42)}`);
35
+
console.log(`The last digit of 105 is ${getLastDigit(105)}`);
36
+
console.log(`The last digit of 806 is ${getLastDigit(806)}`);
30
37
31
38
// This program should tell the user the last digit of each number.
32
39
// Explain why getLastDigit is not working properly - correct the problem
0 commit comments