File tree Expand file tree Collapse file tree 3 files changed +29
-7
lines changed
Sprint-2/2-mandatory-debug Expand file tree Collapse file tree 3 files changed +29
-7
lines changed Original file line number Diff line number Diff line change 11// Predict and explain first...
22
3- // =============> write your prediction here
3+ // =============> In line 6, the word return is missing, I assume.
44
55function multiply ( a , b ) {
66 console . log ( a * b ) ;
77}
88
99console . log ( `The result of multiplying 10 and 32 is ${ multiply ( 10 , 32 ) } ` ) ;
1010
11- // =============> write your explanation here
11+ // =============> $`{multiply(10, 32)}` is undefined.
1212
1313// Finally, correct the code to fix the problem
1414// =============> write your new code here
15+
16+ function multiply ( a , b ) {
17+ return a * b ;
18+ }
19+
20+ console . log ( multiply ( 10 , 32 ) ) ;
Original file line number Diff line number Diff line change 11// Predict and explain first...
2- // =============> write your prediction here
2+ // =============> It will give an error; line 5 and 6 should be in one line.
33
44function sum ( a , b ) {
55 return ;
@@ -8,6 +8,12 @@ function sum(a, b) {
88
99console . log ( `The sum of 10 and 32 is ${ sum ( 10 , 32 ) } ` ) ;
1010
11- // =============> write your explanation here
11+ // =============> The output is undefined because return and a + b are in two different lines.
1212// Finally, correct the code to fix the problem
1313// =============> write your new code here
14+
15+ function sum ( a , b ) {
16+ return a + b ;
17+ }
18+
19+ console . log ( sum ( 10 , 32 ) ) ;
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+ // =============> It will probaby return the last digit as a string.
55
66const num = 103 ;
77
@@ -14,11 +14,21 @@ 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+ // =============> Aha, I was wrong. The outputs for all the console.log is 3
1818// Explain why the output is the way it is
19- // =============> write your explanation here
19+ // =============> because, the function takes 'const num = 103' as input.
2020// Finally, correct the code to fix the problem
2121// =============> write your new code here
2222
23+ function getLastDigit ( num ) {
24+ return num . toString ( ) . slice ( - 1 ) ;
25+ }
26+
2327// This program should tell the user the last digit of each number.
2428// Explain why getLastDigit is not working properly - correct the problem
29+
30+ // This code should be working better. It takes the last digit of the number as a string
31+ // and at last, change that string into a number;
32+ function getLastDigit ( num ) {
33+ return Number ( num . toString ( ) . slice ( - 1 ) ) ;
34+ }
You can’t perform that action at this time.
0 commit comments