Skip to content

Commit 96440cb

Browse files
committed
wrote the code again by fixing error
1 parent 364a5e9 commit 96440cb

1 file changed

Lines changed: 20 additions & 2 deletions

File tree

  • Sprint-3/2-mandatory-debug

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

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,28 @@ console.log(`The last digit of 806 is ${getLastDigit(806)}`);
1717

1818
// Now run the code and compare the output to your prediction
1919
// =============> write the output here
20+
// The output is
21+
// * The last digit of 42 is 3
22+
// * The last digit of 105 is 3
23+
//* The last digit of 806 is 3
2024
// Explain why the output is the way it is
21-
// =============> write your explanation here
25+
// * the output is the way it is because it was taking the num value
26+
// from the variable num that has been declared and initialized outside the function.
27+
// and const num has a global scope.if the function hasn't declared a variable num
28+
// inisde the function it will use the gobaly declared and insialized variable num
2229
// Finally, correct the code to fix the problem
23-
// =============> write your new code here
30+
// =============>function getLastDigit() {
31+
const num = 103;
32+
33+
function getLastDigit(num) {
34+
35+
return num.toString().slice(-1);
36+
}
37+
38+
console.log(`The last digit of 42 is ${getLastDigit(42)}`);
39+
console.log(`The last digit of 105 is ${getLastDigit(105)}`);
40+
console.log(`The last digit of 806 is ${getLastDigit(806)}`);
41+
2442

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

0 commit comments

Comments
 (0)