11// Predict and explain first...
22
33// Predict the output of the following code:
4- // =============> Write your prediction here
4+ // =============> Write your prediction
5+ //It should output string cannot be accessed because we are using normal brackets instead of square brackets
56
67const num = 103 ;
78
@@ -14,11 +15,20 @@ console.log(`The last digit of 105 is ${getLastDigit(105)}`);
1415console . log ( `The last digit of 806 is ${ getLastDigit ( 806 ) } ` ) ;
1516
1617// Now run the code and compare the output to your prediction
17- // =============> write the output here
18+ // =============>The output was 3 for all instead of the last digit of each number.
19+ //
1820// Explain why the output is the way it is
19- // =============> write your explanation here
21+ // =============> This is because we already declared the num variable as a constant
2022// Finally, correct the code to fix the problem
21- // =============> write your new code here
23+ // =============> write your new code here
2224
2325// This program should tell the user the last digit of each number.
2426// Explain why getLastDigit is not working properly - correct the problem
27+ //There was no parameter so the function wasn't running properly.
28+ //function getLastDigit(num) {
29+ // return num.toString().slice(-1);
30+ //}
31+
32+ //console.log(`The last digit of 42 is ${getLastDigit(42)}`);
33+ //console.log(`The last digit of 105 is ${getLastDigit(105)}`);
34+ //console.log(`The last digit of 806 is ${getLastDigit(806)}`);
0 commit comments