File tree Expand file tree Collapse file tree 1 file changed +10
-3
lines changed
Sprint-2/2-mandatory-debug Expand file tree Collapse file tree 1 file changed +10
-3
lines changed Original file line number Diff line number Diff line change 11// Predict and explain first...
22
33// Predict the output of the following code:
4- // =============> Write your prediction here
4+ // =============> num has already been declared as 103, therefore, no other number can be used.
55
66const num = 103 ;
77
@@ -14,11 +14,18 @@ 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+ // =============> The last digit is always 3 because no other inputs are allowed.
1818// Explain why the output is the way it is
19- // =============> write your explanation here
19+ // =============> No other inputs are allowed as num will always be defined as 103.
2020// Finally, correct the code to fix the problem
2121// =============> write your new code here
22+ function getLastDigit ( num ) {
23+ return num . toString ( ) . slice ( - 1 ) ;
24+ }
25+
26+ console . log ( `The last digit of 42 is ${ getLastDigit ( 42 ) } ` ) ;
27+ console . log ( `The last digit of 105 is ${ getLastDigit ( 105 ) } ` ) ;
28+ console . log ( `The last digit of 806 is ${ getLastDigit ( 806 ) } ` ) ;
2229
2330// This program should tell the user the last digit of each number.
2431// Explain why getLastDigit is not working properly - correct the problem
You can’t perform that action at this time.
0 commit comments