Skip to content

Commit f693105

Browse files
committed
all the mandatory debug is done
The prediction and explanation were done
1 parent c9700bf commit f693105

File tree

3 files changed

+30
-12
lines changed

3 files changed

+30
-12
lines changed

Sprint-2/2-mandatory-debug/0.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
11
// Predict and explain first...
22

3-
// =============> write your prediction here
3+
// =============> console.log will print the result because log()will write the message to the console.
4+
//
45

56
function multiply(a, b) {
67
console.log(a * b);
78
}
89

910
console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`);
1011

11-
// =============> write your explanation here
12-
12+
// =============> When testing the code in Node.js, the output was 320 without the message because it was undefined "The result of multiplying 10 and 32 is undefined".
13+
//we need to use return to store the result then print it out.
1314
// Finally, correct the code to fix the problem
14-
// =============> write your new code here
15+
// =============> // Corrected Code:
16+
function multiply(a, b) {
17+
return a * b; // Use 'return' instead of 'console.log'
18+
}
19+
console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`);
20+

Sprint-2/2-mandatory-debug/1.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Predict and explain first...
2-
// =============> write your prediction here
2+
// =============> i think there will be and error message because at doesn't show what value to return so it will be undefined.
33

44
function sum(a, b) {
55
return;
@@ -8,6 +8,10 @@ function sum(a, b) {
88

99
console.log(`The sum of 10 and 32 is ${sum(10, 32)}`);
1010

11-
// =============> write your explanation here
11+
// ============= it should be in the same line after return statement to return the value
1212
// Finally, correct the code to fix the problem
13-
// =============> write your new code here
13+
// =============> corrected code:
14+
function sum(a, b) {
15+
return a + b;
16+
}
17+
console.log(`The sum of 10 and 32 is ${sum(10, 32)}`);

Sprint-2/2-mandatory-debug/2.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Predict and explain first...
22

33
// Predict the output of the following code:
4-
// =============> Write your prediction here
4+
// =============> I predict that the code might not work because I am declaring num outside the function also I am giving num a constant value means it will always be 103
55

66
const num = 103;
77

@@ -14,11 +14,19 @@ console.log(`The last digit of 105 is ${getLastDigit(105)}`);
1414
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+
// =============> the code worked but the answer was 3 i predicted an error message.
1818
// Explain why the output is the way it is
19-
// =============> write your explanation here
19+
// =============> the output was 3 because at the beginning it we declared that num value as 103
2020
// Finally, correct the code to fix the problem
21-
// =============> write your new code here
21+
// =============> corrected code is running the code without giving num any value and add num in the function
22+
23+
function getLastDigit(num) {
24+
return num.toString().slice(-1);
25+
}
26+
27+
console.log(`The last digit of 42 is ${getLastDigit(42)}`);
28+
console.log(`The last digit of 105 is ${getLastDigit(105)}`);
29+
console.log(`The last digit of 806 is ${getLastDigit(806)}`);
2230

2331
// This program should tell the user the last digit of each number.
24-
// Explain why getLastDigit is not working properly - correct the problem
32+
// Explain why getLastDigit is not working properly - it was not working at the start because every time we run the code would slice the last number of the 103 because we declared num as a constant with value 103

0 commit comments

Comments
 (0)