Skip to content

Commit f5a0f60

Browse files
committed
2-mandatory-debug are done.
1 parent 301b638 commit f5a0f60

3 files changed

Lines changed: 25 additions & 0 deletions

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 & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// Predict and explain first...
22
// =============> write your prediction here
3+
// I predict the code will give an error because the sum function does not return a value.
34

45
function sum(a, b) {
56
return;
@@ -9,5 +10,12 @@ function sum(a, b) {
910
console.log(`The sum of 10 and 32 is ${sum(10, 32)}`);
1011

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

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

Lines changed: 10 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

@@ -17,8 +18,17 @@ console.log(`The last digit of 806 is ${getLastDigit(806)}`);
1718
// =============> write the output here
1819
// Explain why the output is the way it is
1920
// =============> write your explanation here
21+
//The function is not using the value passed into it.
2022
// Finally, correct the code to fix the problem
2123
// =============> write your new code here
24+
function getLastDigit(num) {
25+
return num.toString().slice(-1);
26+
}
2227

28+
console.log(`The last digit of 42 is ${getLastDigit(42)}`);
29+
console.log(`The last digit of 105 is ${getLastDigit(105)}`);
30+
console.log(`The last digit of 806 is ${getLastDigit(806)}`);
2331
// This program should tell the user the last digit of each number.
2432
// Explain why getLastDigit is not working properly - correct the problem
33+
// If a function should work with different values → it must have parameters.
34+
// Otherwise it will always use the same fixed value

0 commit comments

Comments
 (0)