|
2 | 2 |
|
3 | 3 | // Predict the output of the following code: |
4 | 4 | // =============> Write your prediction here |
5 | | - //-getting the last digit of 103 |
| 5 | +//-getting the last digit of 103 |
6 | 6 |
|
7 | | - // const num = 103; |
| 7 | +// const num = 103; |
8 | 8 |
|
9 | 9 | // function getLastDigit() { |
10 | 10 | // return num.toString().slice(-1); |
|
16 | 16 |
|
17 | 17 | // Now run the code and compare the output to your prediction |
18 | 18 | // =============> 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 |
| 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 | 22 |
|
23 | 23 | // Explain why the output is the way it is |
24 | | - // -Every time the function calls 103 |
| 24 | +// -Every time the function calls 103 |
25 | 25 | // =============> write your explanation here |
26 | 26 | // Finally, correct the code to fix the problem |
27 | 27 | // =============> write your new code here |
28 | 28 |
|
29 | 29 | // This program should tell the user the last digit of each number. |
30 | 30 | // Explain why getLastDigit is not working properly - correct the problem |
31 | | - //-I removed the unnecessary const num = 103 because the function already receives num as a parameter. |
32 | | - //-The function calculates something and returns it then console.log outside receives that returned value and prints it. |
33 | | - |
34 | | - |
| 31 | +//-I removed the unnecessary const num = 103 because the function already receives num as a parameter. |
| 32 | +//-The function calculates something and returns it then console.log outside receives that returned value and prints it. |
35 | 33 |
|
36 | 34 | function getLastDigit(num) { |
37 | 35 | return num.toString().slice(-1); |
38 | | - |
39 | 36 | } |
40 | 37 | console.log(`The last digit of 42 is ${getLastDigit(42)}`); |
41 | 38 | console.log(`The last digit of 105 is ${getLastDigit(105)}`); |
42 | 39 | console.log(`The last digit of 806 is ${getLastDigit(806)}`); |
43 | | - |
44 | | - |
0 commit comments