Skip to content

Commit 69f740e

Browse files
Fix 2-mandatory-debug/2.js: add num parameter to getLastDigit
1 parent 8f610f3 commit 69f740e

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

  • Sprint-3/2-mandatory-debug

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22

33
// Predict the output of the following code:
44
// =============> Write your prediction here
5+
// I predict every line will say the last digit is 3, because the function
6+
// ignores the number I pass in and always uses num = 103.
57

68
const num = 103;
79

8-
function getLastDigit() {
10+
function getLastDigit(num) {
911
return num.toString().slice(-1);
1012
}
1113

@@ -15,10 +17,17 @@ console.log(`The last digit of 806 is ${getLastDigit(806)}`);
1517

1618
// Now run the code and compare the output to your prediction
1719
// =============> write the output here
20+
// The last digit of 42 is 3
21+
// The last digit of 105 is 3
22+
// The last digit of 806 is 3
1823
// Explain why the output is the way it is
1924
// =============> write your explanation here
25+
// getLastDigit has no parameter, so the argument in getLastDigit(42) is
26+
// ignored. Inside the function, num refers to the global constant
27+
// num = 103, so it always returns "3".
2028
// Finally, correct the code to fix the problem
2129
// =============> write your new code here
22-
30+
// I added num as a parameter: function getLastDigit(num). Now num is the
31+
// value I pass in, not the global num = 103.
2332
// This program should tell the user the last digit of each number.
2433
// Explain why getLastDigit is not working properly - correct the problem

0 commit comments

Comments
 (0)