Skip to content

Commit a86278a

Browse files
committed
2-mandatory-debug are done.
1 parent 70c3018 commit a86278a

3 files changed

Lines changed: 27 additions & 1 deletion

File tree

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

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

33
// =============> write your prediction here
4+
// I predict the code will give an error because the multiply function does not return a value.
45

56
function multiply(a, b) {
67
console.log(a * b);
@@ -9,6 +10,12 @@ function multiply(a, b) {
910
console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`);
1011

1112
// =============> write your explanation here
13+
//The function multiply(a, b) logs the result but does not return anything.
1214

1315
// Finally, correct the code to fix the problem
1416
// =============> write your new code here
17+
function multiply(a, b) {
18+
return a * b;
19+
}
20+
21+
console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`);

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Predict and explain first...
22
// =============> write your prediction here
3-
3+
// I predict the code will give an error because the sum function does not return a value.
44
function sum(a, b) {
55
return;
66
a + b;
@@ -9,5 +9,12 @@ function sum(a, b) {
99
console.log(`The sum of 10 and 32 is ${sum(10, 32)}`);
1010

1111
// =============> write your explanation here
12+
// The function sum(a, b) has a return statement that does not return the result of a + b.
13+
// Instead, it returns undefined because the return statement is followed by a semicolon, which ends the statement before the addition operation is executed.
1214
// Finally, correct the code to fix the problem
1315
// =============> write your new code here
16+
function sum(a, b) {
17+
return a + b;
18+
}
19+
20+
console.log(`The sum of 10 and 32 is ${sum(10, 32)}`);

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
// Predict the output of the following code:
44
// =============> Write your prediction here
5+
//The function has no parameter, so it cannot use input values like 42, 105, 806
56

67
const num = 103;
78

@@ -15,10 +16,21 @@ console.log(`The last digit of 806 is ${getLastDigit(806)}`);
1516

1617
// Now run the code and compare the output to your prediction
1718
// =============> write the output here
19+
// The out will be the last digit of 103 for all three console.log statements, because the function getLastDigit() is using the variable num which is set to 103, instead of using the input values passed to it.
1820
// Explain why the output is the way it is
1921
// =============> write your explanation here
22+
//The function is not using the value passed into it.
2023
// Finally, correct the code to fix the problem
2124
// =============> write your new code here
25+
function getLastDigit(num) {
26+
return num.toString().slice(-1);
27+
}
28+
29+
console.log(`The last digit of 42 is ${getLastDigit(42)}`);
30+
console.log(`The last digit of 105 is ${getLastDigit(105)}`);
31+
console.log(`The last digit of 806 is ${getLastDigit(806)}`);
2232

2333
// This program should tell the user the last digit of each number.
2434
// Explain why getLastDigit is not working properly - correct the problem
35+
// If a function should work with different values → it must have parameters.
36+
// Otherwise it will always use the same fixed value

0 commit comments

Comments
 (0)