2626// Explain why the output is the way it is
2727// =============> write your explanation here
2828
29- // The function is not using the number that is passed into it.
30- // Instead, it always uses the global variable 'num'
31- // which is set to 103.
32- // The last digit of 103 is 3
33- // so the function always returns 3.
29+ // The function does not define a parameter,nso it cannot use the value that is passed into it.
30+ // Instead, it uses the global variable 'num',which is set to 103.
31+ // Even though getLastDigit is called with different numbers,those values are ignored because the function does not accept them.
32+ // That is why it always returns the last digit of 103, which is 3.
3433
3534// Finally, correct the code to fix the problem
3635// =============> write your new code here
@@ -44,15 +43,9 @@ console.log(`The last digit of 105 is ${getLastDigit(105)}`);
4443console . log ( `The last digit of 806 is ${ getLastDigit ( 806 ) } ` ) ;
4544
4645
47- // This program should tell the user the last digit of each number.
48- // Explain why getLastDigit is not working properly - correct the problem
46+ // The function was not working properly because it did not define a parameter.
47+ // Even though values were passed into getLastDigit when it was called,the function could not use them.
48+ // Because there was no parameter, it always used the global variable 'num', which was set to 103. That is why it always returned 3.
49+ // To fix the problem, I added a parameter to the function so it uses the value passed into it instead of the global variable.
4950
50- // The function was not working properly because it did not use
51- // the number that was passed into it.
52- // Instead, it used the global variable 'num',
53- // which was always 103.
54- // That is why it always returned 3.
55- //
56- // To fix the problem, I added a parameter to the function
57- // and used that parameter to calculate the last digit
5851
0 commit comments