11// Predict and explain first...
22
33// Predict the output of the following code:
4- // =============> Write your prediction here
4+ // num is a const so it will al;ways return 3
55
6- const num = 103 ;
6+ // const num = 103;
77
8- function getLastDigit ( ) {
9- return num . toString ( ) . slice ( - 1 ) ;
10- }
8+ // function getLastDigit() {
9+ // return num.toString().slice(-1);
10+ // }
1111
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 ) } ` ) ;
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)}`);
1515
1616// Now run the code and compare the output to your prediction
17- // =============> write the output here
17+ // =============> yes thay all give 3
1818// Explain why the output is the way it is
19- // =============> write your explanation here
19+ // because the variable is a consrent
2020// Finally, correct the code to fix the problem
2121// =============> write your new code here
2222
2323// This program should tell the user the last digit of each number.
2424// Explain why getLastDigit is not working properly - correct the problem
25+
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 ) } ` ) ;
0 commit comments