11// Predict and explain first...
22
33// Predict the output of the following code:
4- // =============> Write your prediction here
4+ // =============> Write your prediction here: my prediction is that the code will log value of 3 because it have constant variable.
55
66const num = 103 ;
77
@@ -14,11 +14,23 @@ console.log(`The last digit of 105 is ${getLastDigit(105)}`);
1414console . log ( `The last digit of 806 is ${ getLastDigit ( 806 ) } ` ) ;
1515
1616// Now run the code and compare the output to your prediction
17- // =============> write the output here
17+ // =============> write the output here : all the console.log values are 3.
18+
1819// Explain why the output is the way it is
19- // =============> write your explanation here
20+ // =============> write your explanation here:it is because the global variable is constant number 103.
21+
2022// Finally, correct the code to fix the problem
21- // =============> write your new code here
23+ // =============> write your new code here : let firstNum = 42;
24+ // let secondeNum = 105;
25+ // let thirdNum = 806;
26+
27+ // function getLastDigit(num) {
28+ // return num.toString().slice(-1);
29+ // }
30+
31+ // console.log(`The last digit of 42 is ${getLastDigit(42)}`);
32+ // console.log(`The last digit of 105 is ${getLastDigit(105)}`);
33+ // console.log(`The last digit of 806 is ${getLastDigit(806)}`);
2234
2335// This program should tell the user the last digit of each number.
2436// Explain why getLastDigit is not working properly - correct the problem
0 commit comments