Skip to content

Commit c2e158f

Browse files
committed
predicted and explained the error. and finally, fixed the code.
1 parent 65fe894 commit c2e158f

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

Sprint-2/1-key-errors/0.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,10 @@ function capitalise(str) {
99
return str;
1010
}
1111

12-
// =============> write your explanation here
13-
// =============> write your new code here
12+
// =============> write your explanation here: when i call the function capitalise with a string input, it shows an error because i am trying to redeclare the variable "str" inside the function, which is already defined as a parameter. this causes a syntax error and we can not redeclare a variable with the same name.
13+
// =============> write your new code here: we can not use let str because str is already the function parameter.
14+
15+
function capitalise(str) {
16+
str = `${str[0].toUpperCase()}${str.slice(1)}`;
17+
return str;
18+
}

Sprint-2/1-key-errors/1.js

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

33
// Why will an error occur when this program runs?
4-
// =============> write your prediction here
4+
// =============> write your prediction here: my prediction: The error will occur because i am trying to redeclare the variable "decimalNumber".//
55

66
// Try playing computer with the example to work out what is going on
77

@@ -14,7 +14,12 @@ function convertToPercentage(decimalNumber) {
1414

1515
console.log(decimalNumber);
1616

17-
// =============> write your explanation here
17+
// =============> write your explanation here: // the error: identifier `decimalNumber` has already been declared. this error shows that identifier has already been declared and we can not redeclare it again.The identifier `decimalNumber` declared in parameter.//
1818

1919
// Finally, correct the code to fix the problem
2020
// =============> write your new code here
21+
// function convertTopercentage(decimalNumber) {
22+
// const percentage = `${decimalNumber * 100}%`;
23+
// return percentage;
24+
// }
25+
// console.log(convertTopercentge(0.5));//

0 commit comments

Comments
 (0)