11// Predict and explain first...
22
33// Predict the output of the following code:
4- // =============> Write your prediction here
4+ // =============> it is declaring num fisrt wich wil work but the function will stop after the
5+ //calculate 103 results. after run Return if the results.
56
6- const num = 103 ;
7+ // I din't predict rigt it gives the results all using the const Num = 103
78
8- function getLastDigit ( ) {
9- return num . toString ( ) . slice ( - 1 ) ;
10- }
9+ // the consolo.log wont work
1110
12- console . log ( `The last digit of 42 is ${ getLastDigit ( 42 ) } ` ) ;
13- console . log ( `The last digit of 105 is ${ getLastDigit ( 105 ) } ` ) ;
14- console . log ( `The last digit of 806 is ${ getLastDigit ( 806 ) } ` ) ;
11+ // const num = 103;
12+
13+ // function getLastDigit() {
14+ // return num.toString().slice(-1);
15+ // }
16+
17+ // console.log(`The last digit of 42 is ${getLastDigit(42)}`);
18+ // console.log(`The last digit of 105 is ${getLastDigit(105)}`);
19+ // console.log(`The last digit of 806 is ${getLastDigit(806)}`);
1520
1621// Now run the code and compare the output to your prediction
1722// =============> write the output here
1823// Explain why the output is the way it is
19- // =============> write your explanation here
24+ // =============> it is using the const 103 for all the results
25+
2026// Finally, correct the code to fix the problem
21- // =============> write your new code here
2227
23- // This program should tell the user the last digit of each number.
24- // Explain why getLastDigit is not working properly - correct the problem
28+
29+
30+ function getLastDigit ( numtoCalculate ) { //give a input to the function to use
31+ const num = numtoCalculate . toString ( ) . slice ( - 1 ) ; //declare a const adding values to what to do
32+ return num ; // return the process
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+
39+ //output
40+ // The last digit of 42 is 2
41+ // The last digit of 105 is 5
42+ // The last digit of 806 is 6
0 commit comments