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
+13Lines changed: 13 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -3,6 +3,7 @@
3
3
// Predict the output of the following code:
4
4
// =============> Write your prediction here
5
5
6
+
// It will return three as a string.
6
7
constnum=103;
7
8
8
9
functiongetLastDigit(){
@@ -15,10 +16,22 @@ 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
+
// "3"
20
+
18
21
// Explain why the output is the way it is
19
22
// =============> write your explanation here
23
+
// This is because they've defined num as 103, and they've used num inside the function, last digit of 103 is 3.
20
24
// Finally, correct the code to fix the problem
21
25
// =============> write your new code here
22
26
27
+
functiongetLastDigit(aNumber){
28
+
returnaNumber.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)}`);
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
37
+
// This is because they've defined num as 103 so the result will always be 3. The arguments should be used instead (42, 105, and 806) and num should not be used.
0 commit comments