Skip to content

Commit 45e94c7

Browse files
committed
exlained the output of the function that takes no parameter in 2.js
1 parent a8778ac commit 45e94c7

File tree

1 file changed

+21
-7
lines changed
  • Sprint-2/2-mandatory-debug

1 file changed

+21
-7
lines changed

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

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,37 @@
22

33
// Predict the output of the following code:
44
// =============> Write your prediction here
5+
// The function will always return 3
56

6-
const num = 103;
7+
// const num = 103;
78

8-
function getLastDigit() {
9-
return num.toString().slice(-1);
10-
}
9+
// function getLastDigit() {
10+
// return num.toString().slice(-1);
11+
// }
1112

12-
console.log(`The last digit of 42 is ${getLastDigit(42)}`);
13-
console.log(`The last digit of 105 is ${getLastDigit(105)}`);
14-
console.log(`The last digit of 806 is ${getLastDigit(806)}`);
13+
// console.log(`The last digit of 42 is ${getLastDigit(42)}`);
14+
// console.log(`The last digit of 105 is ${getLastDigit(105)}`);
15+
// console.log(`The last digit of 806 is ${getLastDigit(806)}`);
1516

1617
// Now run the code and compare the output to your prediction
1718
// =============> write the output here
1819
// Explain why the output is the way it is
1920
// =============> write your explanation here
21+
//getLastDigit takes no parameters.
22+
//Inside the function, will always return the last digit of the global variable num, which is "3".
23+
2024
// Finally, correct the code to fix the problem
2125
// =============> write your new code here
2226

2327
// This program should tell the user the last digit of each number.
2428
// Explain why getLastDigit is not working properly - correct the problem
29+
//Every call ignores the number that is passed in the argument and just returns "3"
30+
const num = 103;
31+
32+
function getLastDigit(num) {
33+
return num.toString().slice(-1);
34+
}
35+
36+
console.log(`The last digit of 42 is ${getLastDigit(42)}`);
37+
console.log(`The last digit of 105 is ${getLastDigit(105)}`);
38+
console.log(`The last digit of 806 is ${getLastDigit(806)}`);

0 commit comments

Comments
 (0)