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
+12Lines changed: 12 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -2,6 +2,7 @@
2
2
3
3
// Predict the output of the following code:
4
4
// =============> Write your prediction here
5
+
// I guess line 7 should have written after line 11. and the num should have been a parameter.
5
6
6
7
constnum=103;
7
8
@@ -15,10 +16,21 @@ console.log(`The last digit of 806 is ${getLastDigit(806)}`);
15
16
16
17
// Now run the code and compare the output to your prediction
17
18
// =============> 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
18
22
// 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.
19
24
// =============> write your explanation here
20
25
// Finally, correct the code to fix the problem
21
26
// =============> write your new code here
27
+
functiongetLastDigit(num){
28
+
returnnum.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)}`);
22
34
23
35
// This program should tell the user the last digit of each number.
24
36
// Explain why getLastDigit is not working properly - correct the problem
0 commit comments