Skip to content

Commit 292e899

Browse files
solving exercise 2-mandatory-debug 2.js
1 parent 0afe2a9 commit 292e899

1 file changed

Lines changed: 15 additions & 4 deletions

File tree

  • Sprint-3/2-mandatory-debug

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

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Predict and explain first...
22

33
// Predict the output of the following code:
4-
// =============> Write your prediction here
4+
// =============> Write your prediction here: This code will throw an error because the function getLastDigit does not take any parameters but we are passing a parameter to it in the console.log statements.
55

66
const num = 103;
77

@@ -14,11 +14,22 @@ console.log(`The last digit of 105 is ${getLastDigit(105)}`);
1414
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 :output
18+
/* The last digit of 42 is 3
19+
The last digit of 105 is 3
20+
The last digit of 806 is 3
21+
*/
1822
// Explain why the output is the way it is
19-
// =============> write your explanation here
23+
// =============> write your explanation here: The funtion return on single value (3) no matter what parameter is passed to it because the function does not take any parameters and it is using the gobal variable num which is set to 103. So the last digit of 103 is always 3.
2024
// Finally, correct the code to fix the problem
2125
// =============> write your new code here
2226

27+
// function getLastDigit(num) {
28+
// return num.toString().slice(-1);
29+
// }
30+
// console.log(`The last digit of 42 is ${getLastDigit(42)}`);
31+
// console.log(`The last digit of 105 is ${getLastDigit(105)}`);
32+
// console.log(`The last digit of 806 is ${getLastDigit(806)}`);
33+
2334
// This program should tell the user the last digit of each number.
24-
// Explain why getLastDigit is not working properly - correct the problem
35+
// Explain why getLastDigit is not working properly - correct the problem : The first declaration of num as constent should be removed and the function getLastDigit should take a parameter num to return the last digit of the number passed to it.

0 commit comments

Comments
 (0)