Skip to content

Commit dcc7246

Browse files
committed
answered 1-key-errors 1.js
1 parent 76ef122 commit dcc7246

3 files changed

Lines changed: 19 additions & 19 deletions

File tree

‎Sprint-3/1-key-errors/0.js‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
// return str;
1212
//}
1313

14-
1514
// =============> write your explanation here
1615
//"str" has been declared in function. In the local scope of original code, str declared again.
1716
//It caused the problem of redeclaration. Delete the "let" in local scope
@@ -21,6 +20,4 @@ function capitalise(str) {
2120
return str;
2221
}
2322

24-
console.log(capitalise('roger'))
25-
26-
23+
console.log(capitalise("roger"));

‎Sprint-3/1-key-errors/1.js‎

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,31 @@
22

33
// Why will an error occur when this program runs?
44
// =============> write your prediction here
5+
// A: There have the problem of redeclaration of the statement of decimalNumber. Local Scope should return to decimalNumber instead.
6+
// To print the code, the code should be console.log(decimalNumber)
57

68
// Try playing computer with the example to work out what is going on
79

8-
function convertToPercentage(decimalNumber) {
9-
const decimalNumber = 0.5;
10-
const percentage = `${decimalNumber * 100}%`;
10+
//function convertToPercentage(decimalNumber) {
11+
// const decimalNumber = 0.5;
12+
// const percentage = `${decimalNumber * 100}%`;
1113

12-
return percentage;
13-
}
14+
// return percentage;
1415

15-
console.log(decimalNumber);
16+
//console.log(decimalNumber);
1617

1718
// =============> write your explanation here
19+
//A: In the local scope, remove "const decimalNumber = 0.5". for the second line of local scope, 'const percentage' should be change to
20+
//'decimalNumber' to avoid redeclaration and refer the correct variable. and return the function to 'decimalNumber'
21+
//finally console.log(convertToPercentage(0.5)) should be used to print the function.
1822

1923
// Finally, correct the code to fix the problem
2024
// =============> write your new code here
25+
26+
function convertToPercentage(decimalNumber) {
27+
decimalNumber = `${decimalNumber * 100}%`;
28+
29+
return decimalNumber;
30+
}
31+
32+
console.log(convertToPercentage(0.5));

‎Sprint-3/prep/passwordCheckerFunction.js‎

Lines changed: 0 additions & 9 deletions
This file was deleted.

0 commit comments

Comments
 (0)