Skip to content

Commit 4dffed1

Browse files
committed
the 2-mandatory-debug has been solved
1 parent dd42ff0 commit 4dffed1

File tree

3 files changed

+49
-24
lines changed

3 files changed

+49
-24
lines changed

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

Lines changed: 11 additions & 6 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+
// =============> it will throw a syntaxerror because I can not use nested console.log.
44

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

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

11-
// =============> write your explanation here
11+
// =============> The result of multiplying 10 and 32 is undefined undefined because If I want to keep the value with me after the function finishes, I must use return.
1212

1313
// Finally, correct the code to fix the problem
1414
// =============> 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+
// =============> It will not return the value.
33

4-
function sum(a, b) {
5-
return;
6-
a + b;
7-
}
4+
// function sum(a, b) {
5+
// return;
6+
// a + b;
7+
// }
88

9-
console.log(`The sum of 10 and 32 is ${sum(10, 32)}`);
9+
// console.log(`The sum of 10 and 32 is ${sum(10, 32)}`);
1010

11-
// =============> write your explanation here
11+
// =============> any think we do after return will not coding.
1212
// Finally, correct the code to fix the problem
1313
// =============> write your new code here
14+
function sum(a, b) {
15+
return a+b;
16+
}
17+
18+
console.log(`The sum of 10 and 32 is ${sum(10, 32)}`);

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

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

33
// Predict the output of the following code:
4-
// =============> Write your prediction here
4+
// =============> first it will convert the number to string then it will slice the last character that function
5+
//then will print
6+
//The last digit of 42 os 2
7+
//The last digit of 105 os 5
8+
//The last digit of 806 os 6
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
1824
// Explain why the output is the way it is
19-
// =============> write your explanation here
25+
// =============> Because the function always takes the global variable witch is 103
26+
//the output will be the same witch 3.
2027
// Finally, correct the code to fix the problem
21-
// =============> write your new code here
28+
// =============> write your new code her
29+
2230

31+
function getLastDigit(num) {
32+
return num.toString().slice(-1);
33+
}
34+
35+
console.log(`The last digit of 42 is ${getLastDigit(42)}`);
36+
console.log(`The last digit of 105 is ${getLastDigit(105)}`);
37+
console.log(`The last digit of 806 is ${getLastDigit(806)}`);
2338
// This program should tell the user the last digit of each number.
2439
// Explain why getLastDigit is not working properly - correct the problem

0 commit comments

Comments
 (0)