11// Predict and explain first...
22
33// Predict the output of the following code:
4- // =============> Write your prediction here
4+ // =============> Write your prediction here .eturn undefiend
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
1717// =============> write the output here
1818// Explain why the output is the way it is
19- // =============> write your explanation here
19+ // =============> write your explanation here. doesn't take any parameters, so it always uses the constant `num = 103`.
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+ function getLastDigit ( num ) {
27+ return num . toString ( ) . slice ( - 1 ) ;
28+ }
29+
30+ console . log ( `The last digit of 42 is ${ getLastDigit ( 42 ) } ` ) ;
31+ console . log ( `The last digit of 105 is ${ getLastDigit ( 105 ) } ` ) ;
32+ console . log ( `The last digit of 806 is ${ getLastDigit ( 806 ) } ` ) ;
0 commit comments