File tree Expand file tree Collapse file tree 1 file changed +11
-0
lines changed
Sprint-2/2-mandatory-debug Expand file tree Collapse file tree 1 file changed +11
-0
lines changed Original file line number Diff line number Diff line change 22
33// Predict the output of the following code:
44// =============> Write your prediction here
5+ // All outputs will be "3" because function has no parameter and always uses global num (103)
56
67const num = 103 ;
78
@@ -15,10 +16,20 @@ console.log(`The last digit of 806 is ${getLastDigit(806)}`);
1516
1617// Now run the code and compare the output to your prediction
1718// =============> write the output here
19+ // The last digit of 42 is 3
20+ // The last digit of 105 is 3
21+ // The last digit of 806 is 3
22+
1823// Explain why the output is the way it is
1924// =============> write your explanation here
25+ // Bug: Function has no parameter, so arguments (42, 105, 806) are ignored. Always uses global num (103)
26+ // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/slice
27+
2028// Finally, correct the code to fix the problem
2129// =============> write your new code here
30+ function getLastDigit ( number ) {
31+ return number . toString ( ) . slice ( - 1 ) ;
32+ }
2233
2334// This program should tell the user the last digit of each number.
2435// Explain why getLastDigit is not working properly - correct the problem
You can’t perform that action at this time.
0 commit comments