Skip to content

Commit 97841e6

Browse files
Completed Sprint-2/2-mandatory-debug
1 parent 49d8ad8 commit 97841e6

3 files changed

Lines changed: 33 additions & 15 deletions

File tree

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

Lines changed: 9 additions & 4 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+
// I predict this will show 'undefined' because the function doesn't return a value.
44

5+
/*
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)}`);
10-
11-
// =============> write your explanation here
11+
*/
12+
// The function doesn't return a value, so the template literal displays '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: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
// Predict and explain first...
2-
// =============> write your prediction here
3-
2+
// I predict this will show 'undefined' because the function doesn't return a value.
3+
/*
44
function sum(a, b) {
55
return;
66
a + b;
77
}
88
99
console.log(`The sum of 10 and 32 is ${sum(10, 32)}`);
10-
11-
// =============> write your explanation here
10+
*/
11+
// The function returns 'undefined', so the template literal displays 'undefined'.
1212
// 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)}`);

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

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

33
// Predict the output of the following code:
4-
// =============> Write your prediction here
5-
4+
// the last digit of any number will always be 3 becuse of the const num = 103;
5+
/*
66
const num = 103;
77
88
function getLastDigit() {
@@ -12,13 +12,22 @@ function getLastDigit() {
1212
console.log(`The last digit of 42 is ${getLastDigit(42)}`);
1313
console.log(`The last digit of 105 is ${getLastDigit(105)}`);
1414
console.log(`The last digit of 806 is ${getLastDigit(806)}`);
15-
15+
*/
1616
// Now run the code and compare the output to your prediction
17-
// =============> write the output here
17+
// =============> output is as predicted, the last digit of any number will always be 3 because of the const num = 103;
1818
// Explain why the output is the way it is
19-
// =============> write your explanation here
19+
// =============> // num is always 103, so the function always returns 3.
2020
// Finally, correct the code to fix the problem
21-
// =============> write your new code here
21+
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)}`);
30+
2231

2332
// This program should tell the user the last digit of each number.
2433
// Explain why getLastDigit is not working properly - correct the problem

0 commit comments

Comments
 (0)