Skip to content

Commit 8c43cd0

Browse files
Update comments in 2.js to clarify function behavior and adjusted the code accordingly
1 parent e93943e commit 8c43cd0

File tree

1 file changed

+20
-10
lines changed
  • Sprint-2/2-mandatory-debug

1 file changed

+20
-10
lines changed

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

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

33
// Predict the output of the following code:
4-
// =============>
4+
// =============> The const num variable is assigned in the global scope and returned in the getLastDigit function.
5+
// The console logs lines 14-16 call the getLastDigit function due to this; the console will log "The last digit of 42 is 3",
6+
// "The last digit of 105 is 3", and
7+
// "The last digit of 806 is 3".
58

6-
const num = 103;
9+
//const num = 103;
710

8-
function getLastDigit() {
11+
//function getLastDigit() {
12+
//return num.toString().slice(-1);
13+
//}
14+
15+
//console.log(`The last digit of 42 is ${getLastDigit(42)}`);
16+
//console.log(`The last digit of 105 is ${getLastDigit(105)}`);
17+
//console.log(`The last digit of 806 is ${getLastDigit(806)}`);
18+
19+
// Now run the code and compare the output to your prediction
20+
// =============> The code performed as expected due to the declaration of num in the global and called in the function
21+
// =============>
22+
// Finally, correct the code to fix the problem
23+
// =============> write your new code here
24+
25+
function getLastDigit(num) {
926
return num.toString().slice(-1);
1027
}
1128

1229
console.log(`The last digit of 42 is ${getLastDigit(42)}`);
1330
console.log(`The last digit of 105 is ${getLastDigit(105)}`);
1431
console.log(`The last digit of 806 is ${getLastDigit(806)}`);
1532

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-
2333
// This program should tell the user the last digit of each number.
2434
// Explain why getLastDigit is not working properly - correct the problem

0 commit comments

Comments
 (0)