Skip to content

Commit 742ac3f

Browse files
debug2604debug2604
authored andcommitted
2-mandatory-debug 2.js edited, result predicted, prediction compared, explained, and code corrected.
1 parent 1b09621 commit 742ac3f

1 file changed

Lines changed: 21 additions & 9 deletions

File tree

  • Sprint-3/2-mandatory-debug

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

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,36 @@
11
// Predict and explain first...
22

33
// Predict the output of the following code:
4-
// =============> Write your prediction here
4+
// =============> Code returns last digit of 103 which is the value of num assigned in global scope.
55

6+
//const num = 103;
7+
8+
//function getLastDigit() {
9+
// return num.toString().slice(-1);
10+
//}
11+
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)}`);
15+
16+
// Now run the code and compare the output to your prediction
17+
// =============>
18+
// The last digit of 42 is 3
19+
// The last digit of 105 is 3
20+
// The last digit of 806 is 3
21+
// Explain why the output is the way it is
22+
// =============> The function refers to the value of `num` assigned in global scope rather than getLastDigit, because 'num' was not a parameter in function name.
23+
// Finally, correct the code to fix the problem
24+
// =============>
625
const num = 103;
726

8-
function getLastDigit() {
27+
function getLastDigit(num) {
928
return num.toString().slice(-1);
1029
}
1130

1231
console.log(`The last digit of 42 is ${getLastDigit(42)}`);
1332
console.log(`The last digit of 105 is ${getLastDigit(105)}`);
1433
console.log(`The last digit of 806 is ${getLastDigit(806)}`);
1534

16-
// Now run the code and compare the output to your prediction
17-
// =============> write the output here
18-
// Explain why the output is the way it is
19-
// =============> write your explanation here
20-
// Finally, correct the code to fix the problem
21-
// =============> write your new code here
22-
2335
// This program should tell the user the last digit of each number.
2436
// Explain why getLastDigit is not working properly - correct the problem

0 commit comments

Comments
 (0)