Skip to content

Commit a23c098

Browse files
explained my predaction and changed the code by adding 'num' as a paramater to the getLastDigit function to make it accept new paramaters when it's called.
1 parent 89c0e11 commit a23c098

File tree

1 file changed

+18
-3
lines changed
  • Sprint-2/2-mandatory-debug

1 file changed

+18
-3
lines changed

Sprint-2/2-mandatory-debug/2.js

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
// Predict the output of the following code:
44
// =============> Write your prediction here
5+
// I predict that because the num variable has been given a constant value, the program will give undefiened when the getLastDigt function called after.
6+
57

68
const num = 103;
79

@@ -14,11 +16,24 @@ console.log(`The last digit of 105 is ${getLastDigit(105)}`);
1416
console.log(`The last digit of 806 is ${getLastDigit(806)}`);
1517

1618
// Now run the code and compare the output to your prediction
17-
// =============> 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
1822
// Explain why the output is the way it is
19-
// =============> write your explanation here
23+
the output give 3 which is the last digit for the constant value declared to the num
24+
because the function getLastDigit doesn't have the num as a paramater to accept it when we call it with the console.log function.
2025
// Finally, correct the code to fix the problem
21-
// =============> write your new code here
26+
27+
const num = 103;
28+
29+
function getLastDigit(num) {
30+
return num.toString().slice(-1);
31+
}
32+
33+
console.log(`The last digit of 42 is ${getLastDigit(42)}`);
34+
console.log(`The last digit of 105 is ${getLastDigit(105)}`);
35+
console.log(`The last digit of 806 is ${getLastDigit(806)}`);
2236

2337
// This program should tell the user the last digit of each number.
2438
// Explain why getLastDigit is not working properly - correct the problem
39+
// because it hasn't been gevine a paramater when it declared but when the num added as a paramater the program give the xpeacted outputs.

0 commit comments

Comments
 (0)