1+ // Predict and explain first...
12
2- The const should not be put into the global frame .
3- if it is set in the global frame , this will result in a single result :3 ,
4- no matter which variables you put in later .
5-
6- The variable insides should have num to match the function expression .
7-
8-
9- My prediction of the result will be all in 3.
3+ // Predict the output of the following code:
4+ // =============> Write your prediction here
105
116const num = 103 ;
127
@@ -18,22 +13,12 @@ console.log(`The last digit of 42 is ${getLastDigit(42)}`);
1813console . log ( `The last digit of 105 is ${ getLastDigit ( 105 ) } ` ) ;
1914console . log ( `The last digit of 806 is ${ getLastDigit ( 806 ) } ` ) ;
2015
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
2122
22-
23- yes the output is all in 3 , because the reason are above .
24-
25-
26-
27- ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
28-
29- function getLastDigit ( num ) {
30- return num . toString ( ) . slice ( - 1 ) ;
31- }
32-
33- console . log ( `The last digit of 42 is ${ getLastDigit ( 42 ) } ` ) ;
34- console . log ( `The last digit of 105 is ${ getLastDigit ( 105 ) } ` ) ;
35- console . log ( `The last digit of 806 is ${ getLastDigit ( 806 ) } ` ) ;
36-
37-
38- After we delete the global frame and put in the variable , we see
39- the result now shows three different digit number .
23+ // This program should tell the user the last digit of each number.
24+ // Explain why getLastDigit is not working properly - correct the problem
0 commit comments