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
+12-4Lines changed: 12 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,7 @@
1
1
// Predict and explain first...
2
2
3
3
// Predict the output of the following code:
4
-
// =============> Write your prediction here
4
+
// =============> Write your prediction here: the function const should write inside the call function.//
5
5
6
6
constnum=103;
7
7
@@ -14,11 +14,19 @@ console.log(`The last digit of 105 is ${getLastDigit(105)}`);
14
14
console.log(`The last digit of 806 is ${getLastDigit(806)}`);
15
15
16
16
// Now run the code and compare the output to your prediction
17
-
// =============> write the output here
17
+
// =============> write the output here: The output is 3 for all three calls.
18
18
// Explain why the output is the way it is
19
-
// =============> write your explanation here
19
+
// =============> write your explanation here: The function getLastDigit is not taking any parameters, so it always uses the outer variable num, which is 103. That's why the output is always 3.
20
20
// Finally, correct the code to fix the problem
21
-
// =============> write your new code here
21
+
// =============> write your new code here:
22
+
23
+
/*function getLastDigit(num) {
24
+
return num.toString().slice(-1);
25
+
}
26
+
27
+
console.log(`The last digit of 42 is ${getLastDigit(42)}`);
28
+
console.log(`The last digit of 105 is ${getLastDigit(105)}`);
29
+
console.log(`The last digit of 806 is ${getLastDigit(806)}`); */
22
30
23
31
// This program should tell the user the last digit of each number.
24
32
// Explain why getLastDigit is not working properly - correct the problem
0 commit comments