Skip to content

Commit 450b81e

Browse files
Predict and put the num inside the get last digit function
1 parent 370f927 commit 450b81e

1 file changed

Lines changed: 26 additions & 8 deletions

File tree

  • Sprint-3/2-mandatory-debug

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

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,42 @@
1-
// Predict and explain first...
1+
// Predict and explain first
2+
// As per the code output should be the last digits of the given number .
23

34
// Predict the output of the following code:
45
// =============> Write your prediction here
6+
//
7+
// The output always be 3 3 3 3 3 3 3 but i thought output should be the last digits.
58

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

8-
function getLastDigit() {
9-
return num.toString().slice(-1);
10-
}
11+
// function getLastDigit() {
12+
// return num.toString().slice(-1);
13+
// }
1114

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+
// 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)}`);
1518

1619
// Now run the code and compare the output to your prediction
1720
// =============> write the output here
21+
// The last digit of 42 is 3
22+
// The last digit of 105 is 3
23+
// The last digit of 806 is 3
1824
// Explain why the output is the way it is
1925
// =============> write your explanation here
26+
// In this variable num is constant and there is no any declaration in function name. Due to this reasons result always be 3.
2027
// Finally, correct the code to fix the problem
2128
// =============> write your new code here
29+
const num = 103;
30+
31+
function getLastDigit(num) {
32+
return num.toString().slice(-1);
33+
}
34+
35+
console.log(`The last digit of 42 is ${getLastDigit(42)}`);
36+
console.log(`The last digit of 105 is ${getLastDigit(105)}`);
37+
console.log(`The last digit of 806 is ${getLastDigit(806)}`);
38+
2239

2340
// This program should tell the user the last digit of each number.
2441
// Explain why getLastDigit is not working properly - correct the problem
42+
// To solve this problems we need to write variable in function.

0 commit comments

Comments
 (0)