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-3/2-mandatory-debug/2.js
+15-4Lines changed: 15 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: This code will throw an error because the function getLastDigit does not take any parameters but we are passing a parameter to it in the console.log statements.
5
5
6
6
constnum=103;
7
7
@@ -14,11 +14,22 @@ 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 :output
18
+
/* The last digit of 42 is 3
19
+
The last digit of 105 is 3
20
+
The last digit of 806 is 3
21
+
*/
18
22
// Explain why the output is the way it is
19
-
// =============> write your explanation here
23
+
// =============> write your explanation here: The funtion return on single value (3) no matter what parameter is passed to it because the function does not take any parameters and it is using the gobal variable num which is set to 103. So the last digit of 103 is always 3.
20
24
// Finally, correct the code to fix the problem
21
25
// =============> write your new code here
22
26
27
+
// function getLastDigit(num) {
28
+
// return num.toString().slice(-1);
29
+
// }
30
+
// console.log(`The last digit of 42 is ${getLastDigit(42)}`);
31
+
// console.log(`The last digit of 105 is ${getLastDigit(105)}`);
32
+
// console.log(`The last digit of 806 is ${getLastDigit(806)}`);
33
+
23
34
// This program should tell the user the last digit of each number.
24
-
// Explain why getLastDigit is not working properly - correct the problem
35
+
// Explain why getLastDigit is not working properly - correct the problem : The first declaration of num as constent should be removed and the function getLastDigit should take a parameter num to return the last digit of the number passed to it.
0 commit comments