Skip to content

Commit ae5326c

Browse files
committed
Fix: Passed num as a parameter inside getLastDigit
1 parent b507572 commit ae5326c

File tree

1 file changed

+5
-5
lines changed
  • Sprint-2/2-mandatory-debug

1 file changed

+5
-5
lines changed

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
// Predict the output of the following code:
44
// =============> Write your prediction here
5-
// II predict that the output will be "The last digit of 42 is 3", "The last digit of 105 is 3",
5+
// II predict that the output will be "The last digit of 42 is 3", "The last digit of 105 is 3",
66
// and "The last digit of 806 is 3" because the function getLastDigit is using the variable num
7-
// which is assigned the value of 103 using const in global scope,
7+
// which is assigned the value of 103 using const in global scope,
88
// so it will always return the last digit of 103 which is 3.
99

1010
// const num = 103;
@@ -26,18 +26,18 @@
2626

2727
// Explain why the output is the way it is
2828
// =============> write your explanation here
29-
// The output is the way it is because the function getLastDigit is using the variable num which is assigned
29+
// The output is the way it is because the function getLastDigit is using the variable num which is assigned
3030
// the value of 103 using const in global scope, and the function definition didn't have an argument to receive the number.
3131

3232
// Finally, correct the code to fix the problem
3333
// =============> write your new code here
3434

35+
const num = 103;
3536

36-
function getLastDigit() {
37+
function getLastDigit(num) {
3738
return num.toString().slice(-1);
3839
}
3940

4041
console.log(`The last digit of 42 is ${getLastDigit(42)}`);
4142
console.log(`The last digit of 105 is ${getLastDigit(105)}`);
4243
console.log(`The last digit of 806 is ${getLastDigit(806)}`);
43-

0 commit comments

Comments
 (0)