Skip to content

Commit 550d3a4

Browse files
Alex JamshidiAlex Jamshidi
authored andcommitted
added solutions to mandatory-debug
1 parent bae8edc commit 550d3a4

3 files changed

Lines changed: 46 additions & 0 deletions

File tree

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

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

33
// =============> write your prediction here
4+
// The multiple function doesn't return anything
5+
// the console log that calls the multiple function will not receive anything back, this
6+
// may cause an error
47

8+
/* Original code:
59
function multiply(a, b) {
610
console.log(a * b);
711
}
812
913
console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`);
14+
*/
1015

1116
// =============> write your explanation here
17+
// code works, however the log gave 'undefined' instead of the multiplication output
18+
// this is because the multiply function doesn't return any value
1219

1320
// Finally, correct the code to fix the problem
21+
1422
// =============> write your new code here
23+
function multiply(a, b) {
24+
return (a * b);
25+
}
26+
27+
console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`);

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,24 @@
11
// Predict and explain first...
22
// =============> write your prediction here
3+
// the sum function won't return anything to the console.log
4+
// because the semicolon ends that line of logic
35

6+
/* Original code:
47
function sum(a, b) {
58
return;
69
a + b;
710
}
811
912
console.log(`The sum of 10 and 32 is ${sum(10, 32)}`);
13+
*/
1014

1115
// =============> write your explanation here
16+
// As before, the function returns "undefined" as nothing is returned
17+
1218
// Finally, correct the code to fix the problem
1319
// =============> write your new code here
20+
function sum(a, b) {
21+
return a + b;
22+
}
23+
24+
console.log(`The sum of 10 and 32 is ${sum(10, 32)}`);

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

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

33
// Predict the output of the following code:
44
// =============> Write your prediction here
5+
// the function does not pass through a parameter, therefore it will always
6+
// call the defined variable num as 103, giving 3 as an output each time
57

8+
/* Original code:
69
const num = 103;
710
811
function getLastDigit() {
@@ -12,13 +15,32 @@ function getLastDigit() {
1215
console.log(`The last digit of 42 is ${getLastDigit(42)}`);
1316
console.log(`The last digit of 105 is ${getLastDigit(105)}`);
1417
console.log(`The last digit of 806 is ${getLastDigit(806)}`);
18+
*/
1519

1620
// Now run the code and compare the output to your prediction
1721
// =============> write the output here
22+
/*
23+
The last digit of 42 is 3
24+
The last digit of 105 is 3
25+
The last digit of 806 is 3
26+
*/
27+
1828
// Explain why the output is the way it is
1929
// =============> write your explanation here
30+
// there is no parameter for the function
31+
2032
// Finally, correct the code to fix the problem
2133
// =============> write your new code here
2234

35+
const num = 103;
36+
37+
function getLastDigit(num) {
38+
return num.toString().slice(-1);
39+
}
40+
41+
console.log(`The last digit of 42 is ${getLastDigit(42)}`);
42+
console.log(`The last digit of 105 is ${getLastDigit(105)}`);
43+
console.log(`The last digit of 806 is ${getLastDigit(806)}`);
44+
2345
// This program should tell the user the last digit of each number.
2446
// Explain why getLastDigit is not working properly - correct the problem

0 commit comments

Comments
 (0)