You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// =============> I predict the function will be called when the console try to print the sentence 'The result....'. In this case, two values 10 and 32 are inserted to this function. And a result will be calculated '10x32'. But I expected the function won't work exactly what people expect because I expect the result will be return instead of console print it to me. If I change this, I will expect the code works then.
4
4
5
5
functionmultiply(a,b){
6
6
console.log(a*b);
7
7
}
8
8
9
9
console.log(`The result of multiplying 10 and 32 is ${multiply(10,32)}`);
10
10
11
-
// =============> write your explanation here
11
+
// =============> When I run this code, the sentence 'The result of multiplying 10 and 32 is undefined' comes to me. I think it is caused by the missed return statement and no value will be returned to this result in the sentence.
12
12
13
13
// Finally, correct the code to fix the problem
14
-
// =============> write your new code here
14
+
// =============> function multiply(a, b) {
15
+
// =============> return a * b;
16
+
// =============> }
17
+
18
+
console.log(`The result of multiplying 10 and 32 is ${multiply(10,32)}`);
// =============> I predict an error will occur as the line 5 and 6 seems not to be a correct syntax to return a value that the function needs to.
3
3
4
4
functionsum(a,b){
5
5
return;
@@ -8,6 +8,10 @@ function sum(a, b) {
8
8
9
9
console.log(`The sum of 10 and 32 is ${sum(10,32)}`);
10
10
11
-
// =============> write your explanation here
11
+
// =============> When I run the code, 'The sum of 10 and 32 is undefined' comes, it is because the line 5 and 6 need to be merge to properly return a value.
12
12
// Finally, correct the code to fix the problem
13
-
// =============> write your new code here
13
+
// =============> function sum(a, b) {
14
+
// =============> return a + b;
15
+
// =============> }
16
+
17
+
// =============> console.log(`The sum of 10 and 32 is ${sum(10, 32)}`);
Copy file name to clipboardExpand all lines: Sprint-2/2-mandatory-debug/2.js
+11-4Lines changed: 11 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,7 @@
1
1
// Predict and explain first...
2
2
3
3
// Predict the output of the following code:
4
-
// =============> Write your prediction here
4
+
// =============> I predict the code function in this file will extract the last digit of number for us. The function itself seems working fine and the function call statement should work fine too. But the issue is that there is a declaration of variable 'num' on line 6 which will fix all the input to the function statement so we cannot expect the correct return value in this code.
5
5
6
6
constnum=103;
7
7
@@ -14,11 +14,18 @@ console.log(`The last digit of 105 is ${getLastDigit(105)}`);
14
14
console.log(`The last digit of 806 is ${getLastDigit(806)}`);
15
15
16
16
// Now run the code and compare the output to your prediction
17
-
// =============> write the output here
17
+
// =============> As expected, all the return value is '3' for the function with difference parameter called.
18
18
// Explain why the output is the way it is
19
-
// =============> write your explanation here
19
+
// =============> As the declared variable 'num' has been assigned with a fixed value.
// =============> console.log(`The last digit of 42 is ${getLastDigit(42)}`);
26
+
// =============> console.log(`The last digit of 105 is ${getLastDigit(105)}`);
27
+
// =============> console.log(`The last digit of 806 is ${getLastDigit(806)}`);
22
28
23
29
// This program should tell the user the last digit of each number.
24
30
// Explain why getLastDigit is not working properly - correct the problem
31
+
//The overall syntax in this code works fine and it trigger no error. But the code doesn't work properly and doesn't show the digit we expected is because it tried to declare the num with a fixed number in the beginning of code instead of putting it in the parenthesis of function. It makes the parameter cannot be successfully pass to the function, so the outcome will not be right.
0 commit comments