Skip to content

Commit b7707e3

Browse files
committed
In 2-Mandatory-debug/2.js, predicted the case explained the scenario and modified the code
1 parent 4ef9f59 commit b7707e3

File tree

1 file changed

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

1 file changed

+21
-10
lines changed

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

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

33
// Predict the output of the following code:
4-
// =============> Write your prediction here
4+
// =============> The code will first return 3 as string and after calling the function getLastDigit,
5+
// it will not return anything because every number pased will be changed to string.
56

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

8-
function getLastDigit() {
9+
// function getLastDigit() {
10+
// return num.toString().slice(-1);
11+
// }
12+
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)}`);
16+
17+
// Now run the code and compare the output to your prediction
18+
// =============> The last digit of 42 is 3 three times..
19+
// // =============> my prediction was somehow closer but not exact, the case is parameter num needs to be with the getLastDifit
20+
// function instead of const num = 103.
21+
// Finally, correct the code to fix the problem
22+
// =============> write your new code here
23+
24+
function getLastDigit(num) {
925
return num.toString().slice(-1);
1026
}
1127

1228
console.log(`The last digit of 42 is ${getLastDigit(42)}`);
1329
console.log(`The last digit of 105 is ${getLastDigit(105)}`);
1430
console.log(`The last digit of 806 is ${getLastDigit(806)}`);
1531

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-
2332
// This program should tell the user the last digit of each number.
2433
// Explain why getLastDigit is not working properly - correct the problem
34+
35+
//the case is parameter num needs to be with the getLastDigit function instead of const num = 103.

0 commit comments

Comments
 (0)