Skip to content

Commit f682c6c

Browse files
committed
Complete 2-mandatory-debug
1 parent 47f18bb commit f682c6c

File tree

3 files changed

+48
-27
lines changed

3 files changed

+48
-27
lines changed

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

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

3-
// =============> write your prediction here
3+
// The result of a * b will be printed to the console
4+
// Since the function does not return any value, it will return undefined
45

5-
function multiply(a, b) {
6-
console.log(a * b);
7-
}
6+
// function multiply(a, b) {
7+
// console.log(a * b);
8+
// }
89

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

11-
// =============> write your explanation here
12+
// Because the function is evaluated before the string is printed to the console, it will log the result of a * b to the console first, but because it does not return a value, the next console.log of the string will print 'The result of multiplying 10 and 32 is undefined'
1213

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

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

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
// Predict and explain first...
2-
// =============> write your prediction here
2+
// The function is intended to take 2 arguments and return the sum
3+
// it will return undefined
34

5+
// function sum(a, b) {
6+
// return;
7+
// a + b;
8+
// }
9+
10+
// console.log(`The sum of 10 and 32 is ${sum(10, 32)}`);
11+
12+
// it currently has a return statement that ends the function prematurely, causing it to return undefined
13+
// Finally, correct the code to fix the problem
414
function sum(a, b) {
5-
return;
6-
a + b;
15+
return a + b;
716
}
817

918
console.log(`The sum of 10 and 32 is ${sum(10, 32)}`);
10-
11-
// =============> write your explanation here
12-
// Finally, correct the code to fix the problem
13-
// =============> write your new code here

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

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,35 @@
11
// Predict and explain first...
2+
// The function intends to take a number and return it's last digit
3+
// Each call of the function will return the same result
24

35
// Predict the output of the following code:
4-
// =============> Write your prediction here
6+
// 'The last digit of 42 is 3'
7+
// 'The last digit of 105 is 3'
8+
// 'The last digit of 806 is 3'
59

6-
const num = 103;
10+
// const num = 103;
711

8-
function getLastDigit() {
9-
return num.toString().slice(-1);
10-
}
12+
// function getLastDigit() {
13+
// return num.toString().slice(-1);
14+
// }
1115

12-
console.log(`The last digit of 42 is ${getLastDigit(42)}`);
13-
console.log(`The last digit of 105 is ${getLastDigit(105)}`);
14-
console.log(`The last digit of 806 is ${getLastDigit(806)}`);
16+
// console.log(`The last digit of 42 is ${getLastDigit(42)}`);
17+
// console.log(`The last digit of 105 is ${getLastDigit(105)}`);
18+
// console.log(`The last digit of 806 is ${getLastDigit(806)}`);
1519

1620
// Now run the code and compare the output to your prediction
17-
// =============> write the output here
21+
// 'The last digit of 42 is 3'
22+
// 'The last digit of 105 is 3'
23+
// 'The last digit of 806 is 3'
24+
1825
// Explain why the output is the way it is
19-
// =============> write your explanation here
26+
// Because the function was not correctly defined to accept an argument, It was using a fixed variable instead
27+
2028
// Finally, correct the code to fix the problem
21-
// =============> write your new code here
29+
function getLastDigit(num) {
30+
return num.toString().slice(-1);
31+
}
2232

23-
// This program should tell the user the last digit of each number.
24-
// Explain why getLastDigit is not working properly - correct the problem
33+
console.log(`The last digit of 42 is ${getLastDigit(42)}`);
34+
console.log(`The last digit of 105 is ${getLastDigit(105)}`);
35+
console.log(`The last digit of 806 is ${getLastDigit(806)}`);

0 commit comments

Comments
 (0)