Skip to content

Commit ae15e29

Browse files
committed
Finished mandatory debug 2
1 parent f5b1cd8 commit ae15e29

File tree

1 file changed

+12
-4
lines changed
  • Sprint-2/2-mandatory-debug

1 file changed

+12
-4
lines changed

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

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Predict and explain first...
22

33
// Predict the output of the following code:
4-
// =============> Write your prediction here
4+
// =============> Write your prediction here: The function getLastDigit doesn't take any parameters, so it will always return the last digit of the number 103, 3.
55

66
const num = 103;
77

@@ -14,11 +14,19 @@ console.log(`The last digit of 105 is ${getLastDigit(105)}`);
1414
console.log(`The last digit of 806 is ${getLastDigit(806)}`);
1515

1616
// Now run the code and compare the output to your prediction
17-
// =============> write the output here
17+
// =============> write the output here: The last digit of 42 is 3. The last digit of 105 is 3. The last digit of 806 is 3
1818
// Explain why the output is the way it is
19-
// =============> write your explanation here
19+
// =============> write your explanation here: The function getLastDigit doesn't take any parameters, so it always returns the last digit of the variable num, which is 103.
2020
// Finally, correct the code to fix the problem
21-
// =============> write your new code here
21+
// =============> write your new code here:
22+
// function getLastDigit(num) {
23+
// return num.toString().slice(-1);
24+
// }
25+
26+
// console.log(`The last digit of 42 is ${getLastDigit(42)}`);
27+
// console.log(`The last digit of 105 is ${getLastDigit(105)}`);
28+
// console.log(`The last digit of 806 is ${getLastDigit(806)}`);
2229

2330
// This program should tell the user the last digit of each number.
2431
// Explain why getLastDigit is not working properly - correct the problem
32+
// The function getLastDigit is not working properly because it does not take any parameters, so it always returns the last digit of the variable num, which is 103.

0 commit comments

Comments
 (0)