|
1 | 1 | // Predict and explain first... |
2 | 2 |
|
3 | 3 | // Predict the output of the following code: |
4 | | -// =============> Write your prediction here |
| 4 | +// =============> The last digit will be 3 with all the function. |
5 | 5 |
|
| 6 | +// Now run the code and compare the output to your prediction |
| 7 | +// =============> write the output here |
| 8 | +// Explain why the output is the way it is |
| 9 | +// =============> A function "getLastDigit" must declare parameters to receive arguments. |
| 10 | + //If it doesn’t, any arguments passed in are ignored. |
| 11 | +// Finally, correct the code to fix the problem |
| 12 | +// =============> write your new code here |
6 | 13 | const num = 103; |
7 | 14 |
|
8 | | -function getLastDigit() { |
| 15 | +function getLastDigit(num) { |
9 | 16 | return num.toString().slice(-1); |
10 | 17 | } |
11 | 18 |
|
12 | 19 | console.log(`The last digit of 42 is ${getLastDigit(42)}`); |
13 | 20 | console.log(`The last digit of 105 is ${getLastDigit(105)}`); |
14 | 21 | console.log(`The last digit of 806 is ${getLastDigit(806)}`); |
15 | 22 |
|
16 | | -// Now run the code and compare the output to your prediction |
17 | | -// =============> write the output here |
18 | | -// Explain why the output is the way it is |
19 | | -// =============> write your explanation here |
20 | | -// Finally, correct the code to fix the problem |
21 | | -// =============> write your new code here |
22 | | - |
23 | 23 | // This program should tell the user the last digit of each number. |
24 | 24 | // Explain why getLastDigit is not working properly - correct the problem |
0 commit comments