Skip to content

Commit 989aa0b

Browse files
committed
2-mandatory-debug sprint3 completed
1 parent e67a022 commit 989aa0b

3 files changed

Lines changed: 43 additions & 5 deletions

File tree

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

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

3-
// =============> write your prediction here
3+
// =============> We will log the result in a console but function won't return it as a value.
4+
// console.log only displays the result, it does not return it from the function.
45

6+
/*
57
function multiply(a, b) {
68
console.log(a * b);
79
}
10+
console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`);
11+
*/
812

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

1114
// =============> write your explanation here
1215

16+
//We need to return a * b so the result can be used where the function is called.
17+
1318
// Finally, correct the code to fix the problem
1419
// =============> write your new code here
20+
function multiply(a, b) {
21+
return a * b;
22+
}
23+
24+
console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`);

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
11
// Predict and explain first...
2-
// =============> write your prediction here
3-
2+
// =============> return on its own means that the function ends without returning a value, so the result is undefined.
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+
*/
1011

1112
// =============> write your explanation here
13+
// return on it's own means that the function wont refer to parameters and will come up as undefined. a+ b is never reached because it comes after return.
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-3/2-mandatory-debug/2.js‎

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

33
// Predict the output of the following code:
4-
// =============> Write your prediction here
4+
// =============> The last digit of 42 is 3
5+
// The last digit of 105 is 3
6+
// The last digit of 806 is 3
57

8+
/*
69
const num = 103;
710
811
function getLastDigit() {
@@ -12,13 +15,31 @@ 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+
/*The last digit of 42 is 3
23+
The last digit of 105 is 3
24+
The last digit of 806 is 3
25+
*/
1826
// Explain why the output is the way it is
1927
// =============> write your explanation here
28+
//The output is this way as there is a num assigned before the function and function don't use the parameter num,
29+
//so the output would only be the return of slice value for const num before the function.
30+
2031
// Finally, correct the code to fix the problem
2132
// =============> write your new code here
33+
const num = 103;
34+
35+
function getLastDigit(num) {
36+
return num.toString().slice(-1);
37+
}
38+
39+
console.log(`The last digit of 42 is ${getLastDigit(42)}`);
40+
console.log(`The last digit of 105 is ${getLastDigit(105)}`);
41+
console.log(`The last digit of 806 is ${getLastDigit(806)}`);
2242

2343
// This program should tell the user the last digit of each number.
2444
// Explain why getLastDigit is not working properly - correct the problem
45+
//Function was not working correctly as it was returning num slice for const num that was assigned before the function, function should use parameter num to work correctly.

0 commit comments

Comments
 (0)