|
1 | 1 | // Predict and explain first... |
2 | 2 |
|
3 | | -// Predict the output of the following code: |
4 | | -// =============> Write your prediction here |
| 3 | +// IPredict the output of the following code: |
| 4 | +// I am predicting an error because the variable const num = 103 is outside the function. =============> Write your prediction here |
| 5 | +// There is no parameters in the function condition |
5 | 6 |
|
6 | | -const num = 103; |
7 | 7 |
|
8 | | -function getLastDigit() { |
| 8 | + |
| 9 | +// Now run the code and compare the output to your prediction |
| 10 | +// when i ran the output i got 3,3,3.=============> write the output here |
| 11 | +// Explain why the output is the way it is |
| 12 | +// the argument for the console.log is ignored because "getlastDigit" does not have a parameter. =============> write your explanation here |
| 13 | +// Finally, correct the code to fix the problem |
| 14 | +function getLastDigit(num) { |
9 | 15 | return num.toString().slice(-1); |
10 | 16 | } |
11 | 17 |
|
12 | 18 | console.log(`The last digit of 42 is ${getLastDigit(42)}`); |
13 | 19 | console.log(`The last digit of 105 is ${getLastDigit(105)}`); |
14 | 20 | console.log(`The last digit of 806 is ${getLastDigit(806)}`); |
15 | | - |
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 | 21 | // =============> write your new code here |
22 | 22 |
|
23 | 23 | // This program should tell the user the last digit of each number. |
|
0 commit comments