22
33// Predict the output of the following code:
44// =============> Write your prediction here
5- /* I predict that the three call are giving
6- The last digit of 42 is 2
7- The last digit of 105 is 5
8- The last digit of 806 is 6 */
95
10- /* const num = 103;
6+ const num = 103 ;
117
128function getLastDigit ( ) {
139 return num . toString ( ) . slice ( - 1 ) ;
@@ -16,25 +12,13 @@ function getLastDigit() {
1612console . log ( `The last digit of 42 is ${ getLastDigit ( 42 ) } ` ) ;
1713console . log ( `The last digit of 105 is ${ getLastDigit ( 105 ) } ` ) ;
1814console . log ( `The last digit of 806 is ${ getLastDigit ( 806 ) } ` ) ;
19- */
15+
2016// Now run the code and compare the output to your prediction
2117// =============> write the output here
22- /* The last digit of 42 is 3
23- The last digit of 105 is 3
24- The last digit of 806 is 3 */
2518// Explain why the output is the way it is
2619// =============> write your explanation here
27- /* because the num is determined at fires and 103 is given to the num. as a result we see the same result.*/
2820// Finally, correct the code to fix the problem
2921// =============> write your new code here
3022
31- function getLastDigit ( num ) {
32- return num . toString ( ) . slice ( - 1 ) ;
33- }
34-
35- console . log ( `The last digit of 42 is ${ getLastDigit ( 42 ) } ` ) ;
36- console . log ( `The last digit of 105 is ${ getLastDigit ( 105 ) } ` ) ;
37- console . log ( `The last digit of 806 is ${ getLastDigit ( 806 ) } ` ) ;
38-
3923// This program should tell the user the last digit of each number.
4024// Explain why getLastDigit is not working properly - correct the problem
0 commit comments