Skip to content

Commit ba0a3a8

Browse files
committed
2.js
1 parent 7229e50 commit ba0a3a8

File tree

1 file changed

+23
-9
lines changed
  • Sprint-2/2-mandatory-debug

1 file changed

+23
-9
lines changed

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

Lines changed: 23 additions & 9 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 output will be:
6+
// The last digit of 42 is 3
7+
// The last digit of 105 is 3
8+
// The last digit of 806 is 3
9+
// Because getLastDigit always uses the global variable num (103) and ignores the argument.
510

6-
const num = 103;
711

8-
function getLastDigit() {
9-
return num.toString().slice(-1);
10-
}
12+
// const num = 103;
1113

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)}`);
14+
// function getLastDigit() {
15+
// return num.toString().slice(-1);
16+
// }
17+
18+
// console.log(`The last digit of 42 is ${getLastDigit(42)}`);
19+
// console.log(`The last digit of 105 is ${getLastDigit(105)}`);
20+
// console.log(`The last digit of 806 is ${getLastDigit(806)}`);
1521

16-
// Now run the code and compare the output to your prediction
22+
// // Now run the code and compare the output to your prediction
1723
// =============> write the output here
1824
// Explain why the output is the way it is
1925
// =============> write your explanation here
26+
// The function getLastDigit does not accept any parameters and always uses the global variable num (103).
27+
// So, regardless of the argument passed, it always returns the last digit of 103, which is "3".
28+
2029
// Finally, correct the code to fix the problem
2130
// =============> write your new code here
22-
31+
function getLastDigit(num) {
32+
return num.toString().slice(-1);
33+
}
34+
console.log(`The last digit of 42 is ${getLastDigit(42)}`);
35+
console.log(`The last digit of 105 is ${getLastDigit(105)}`);
36+
console.log(`The last digit of 806 is ${getLastDigit(806)}`);
2337
// This program should tell the user the last digit of each number.
2438
// Explain why getLastDigit is not working properly - correct the problem

0 commit comments

Comments
 (0)