Skip to content

Commit 6079d67

Browse files
committed
debug 2.js in Sprint 2 > 2-mandatory-debug
1 parent de2b780 commit 6079d67

1 file changed

Lines changed: 15 additions & 3 deletions

File tree

  • Sprint-2/2-mandatory-debug

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

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

33
// Predict the output of the following code:
4-
// =============> Write your prediction here
4+
// =============> we did not give the function a parameter, and we are returning the last digit of 103 (num) instead of all the different numbers passed into this function
55

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

88
function getLastDigit() {
99
return num.toString().slice(-1);
@@ -15,10 +15,22 @@ console.log(`The last digit of 806 is ${getLastDigit(806)}`);
1515

1616
// Now run the code and compare the output to your prediction
1717
// =============> write the output here
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+
// =============> because we did not define a parameter in the function to be used, instead we are using a variable that is declared to have a certain value (103) so the function will always perform the calculation on this variable
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+
31+
console.log(`The last digit of 42 is ${getLastDigit(42)}`);
32+
console.log(`The last digit of 105 is ${getLastDigit(105)}`);
33+
console.log(`The last digit of 806 is ${getLastDigit(806)}`);
34+
2335
// This program should tell the user the last digit of each number.
2436
// Explain why getLastDigit is not working properly - correct the problem

0 commit comments

Comments
 (0)