Skip to content

Commit 3dc5d02

Browse files
committed
answered 2-mandatory-debugs. 2.js
1 parent bcb1815 commit 3dc5d02

3 files changed

Lines changed: 32 additions & 11 deletions

File tree

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

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

33
// =============> write your prediction here
4-
// local scope code did not return to global.
4+
// A: The result of multiplying 10 and 32 is 320. But local scope code did not return to global.
55

66
//function multiply(a, b) {
77
// console.log(a * b);
@@ -10,7 +10,7 @@
1010
//console.log(`The result of multiplying 10 and 32 is ${multiply(10, 32)}`);
1111

1212
// =============> write your explanation here
13-
// The calculation of the a * b should apply the the statement (`The result of multiplying 10 and 32 is ${multiply(10, 32)}`).
13+
// A: The calculation of the a * b should apply the the statement (`The result of multiplying 10 and 32 is ${multiply(10, 32)}`).
1414
// because code on local scope did not return to global. The global cannot apply the result of local.
1515

1616
// Finally, correct the code to fix the problem

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Predict and explain first...
22
// =============> write your prediction here
3-
// The result of the function supposed to print 'The sum of 10 and 32 is 42' local scope should be return to sum.
3+
// A: The result of the function supposed to print 'The sum of 10 and 32 is 42' local scope should be return to sum.
44

55
//function sum(a, b) {
66
// return;
@@ -10,7 +10,7 @@
1010
console.log(`The sum of 10 and 32 is ${sum(10, 32)}`);
1111

1212
// =============> write your explanation here
13-
// the answer is undefined because of local scope code did not return to global (sum). semicolon of return need to be removed.
13+
// A: the answer is undefined because of local scope code did not return to global (sum). semicolon of return need to be removed.
1414
// Finally, correct the code to fix the problem
1515
// =============> write your new code here
1616
function sum(a, b) {

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

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,44 @@
22

33
// Predict the output of the following code:
44
// =============> Write your prediction here
5+
// A: The function supposed to print the last digit of 42, 105 and 806 which is 2, 5, 6. But the function could not run smooth
6+
// because of the variable "num" has been declared.
57

6-
const num = 103;
8+
//const num = 103;
79

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

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)}`);
14+
//console.log(`The last digit of 42 is ${getLastDigit(42)}`);
15+
//console.log(`The last digit of 105 is ${getLastDigit(105)}`);
16+
//console.log(`The last digit of 806 is ${getLastDigit(806)}`);
17+
18+
// This program should tell the user the last digit of each number.
19+
// Explain why getLastDigit is not working properly - correct the problem
1520

1621
// Now run the code and compare the output to your prediction
1722
// =============> write the output here
23+
//A: The last digit of 42 is 3
24+
//The last digit of 105 is 3
25+
//The last digit of 806 is 3
26+
1827
// Explain why the output is the way it is
1928
// =============> write your explanation here
29+
// A: because num has been declared for 103 so the function could only get the last digit of 42, 105 and 806.
30+
2031
// Finally, correct the code to fix the problem
2132
// =============> write your new code here
2233

34+
function getLastDigit(number) {
35+
return number.toString().slice(-1);
36+
}
37+
38+
console.log(`The last digit of 42 is ${getLastDigit(42)}`);
39+
console.log(`The last digit of 105 is ${getLastDigit(105)}`);
40+
console.log(`The last digit of 806 is ${getLastDigit(806)}`);
41+
2342
// This program should tell the user the last digit of each number.
2443
// Explain why getLastDigit is not working properly - correct the problem
44+
// A: it is because num has been strictly declared as 103 before. and the value is console log could be be applied to function.
45+
// To fix this parameter of getLastDigit should assign for val as a placeholder to allow different value

0 commit comments

Comments
 (0)