Skip to content

Commit 43b3249

Browse files
committed
mandatory debug 1.2
1 parent 60f078f commit 43b3249

File tree

1 file changed

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

1 file changed

+19
-10
lines changed

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

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

33
// Predict the output of the following code:
4-
// =============> Write your prediction here
4+
// =============> Write your prediction here: We are trying to convert the last figure (last index) of a number to a String. We will surely get "2", "5" and "6"
55

6-
const num = 103;
6+
// const num = 103;
77

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

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)}`);
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)}`);
1515

1616
// Now run the code and compare the output to your prediction
17-
// =============> write the output here
17+
// =============> write the output here: After running our code, we saw that it printed "3" all over. Which comes from our initial declaration of num = 103
1818
// Explain why the output is the way it is
19-
// =============> write your explanation here
19+
// =============> write your explanation here: We have declared num as a const which makes it unchangeable through out. We cannot redeclare it. The second thing is that we will need to add num inside of the parameter of the function.
2020
// Finally, correct the code to fix the problem
2121
// =============> write your new code here
22+
let num = 103;
23+
24+
function getLastDigit(num) {
25+
return num.toString().slice(-1);
26+
}
27+
28+
console.log(`The last digit of 42 is ${getLastDigit(42)}`);
29+
console.log(`The last digit of 105 is ${getLastDigit(105)}`);
30+
console.log(`The last digit of 806 is ${getLastDigit(806)}`);
2231

2332
// This program should tell the user the last digit of each number.
2433
// Explain why getLastDigit is not working properly - correct the problem

0 commit comments

Comments
 (0)