|
1 | 1 | // Predict and explain first... |
2 | | -// |
| 2 | + |
3 | 3 | // Predict the output of the following code: |
4 | | -// =============> Write your prediction here i thing this one will work |
| 4 | +// =============> Write your prediction here |
5 | 5 |
|
6 | | -/*const num = 103; |
| 6 | +const num = 103; |
7 | 7 |
|
8 | 8 | function getLastDigit() { |
9 | 9 | return num.toString().slice(-1); |
10 | 10 | } |
11 | 11 |
|
12 | 12 | console.log(`The last digit of 42 is ${getLastDigit(42)}`); |
13 | 13 | console.log(`The last digit of 105 is ${getLastDigit(105)}`); |
14 | | -console.log(`The last digit of 806 is ${getLastDigit(806)}`);*/ |
| 14 | +console.log(`The last digit of 806 is ${getLastDigit(806)}`); |
15 | 15 |
|
16 | 16 | // Now run the code and compare the output to your prediction |
17 | 17 | // =============> write the output here |
18 | | -// i was incorrect the const at the top makes them all come out as 3 |
19 | 18 | // Explain why the output is the way it is |
20 | 19 | // =============> write your explanation here |
21 | | -// the constant can't be changed by the code block and num needs to be part of the function |
22 | 20 | // Finally, correct the code to fix the problem |
23 | 21 | // =============> write your new code here |
24 | 22 |
|
25 | | -let num = 0; |
26 | | -function getLastDigit(num) { |
27 | | - return num.toString().slice(-1); |
28 | | -} |
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 | | - |
34 | | - |
35 | 23 | // This program should tell the user the last digit of each number. |
36 | 24 | // Explain why getLastDigit is not working properly - correct the problem |
0 commit comments