Skip to content

Commit f18f2af

Browse files
in key errors 1.js explained the predicated errors and explained the syntax error occurs when the program runs and write the new code that doesn't redeclare the decimalNumber in a const variable in inside the function
1 parent 3372770 commit f18f2af

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
// Predict and explain first...
2-
// =============> write your prediction here
2+
// =============>
33

44
// call the function capitalise with a string input
55
// interpret the error message and figure out why an error is occurring
66

77
function capitalise(str) {
8-
let str = `${str[0].toUpperCase()}${str.slice(1)}`;
9-
return str;
8+
let newStr = `${str[0].toUpperCase()}${str.slice(1)}`;
9+
return newStr;
1010
}
1111

12+
1213
// =============> write your explanation here
1314
// =============> write your new code here

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

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
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: the error will occur because the variable decimslNumber gevine a value of 0.5
5+
with a const declaration and this will make an error if the brograme given a diffrent value for the decimalNumber.
56

67
// Try playing computer with the example to work out what is going on
78

@@ -14,7 +15,18 @@ function convertToPercentage(decimalNumber) {
1415

1516
console.log(decimalNumber);
1617

17-
// =============> write your explanation here
18+
// =============> write your explanation here
19+
when the program run it give a SyntaxError: Identifier 'decimalNumber' has already been declared. This is because the variable decimalNumber is declared twice in the function
20+
convertToPercentage, and inside the function with the constant varible CSSStyleDeclaration. also using the function name decimalNumber with the console.log function will give an error because the function name should be
21+
to fix this error we can remove the const variable declaration of decimalNumber from the function and use the function name
22+
'ConvertToPercentage' to recall the function and pass the value of the decimalNumber.CSSStyleDeclaration
1823

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

0 commit comments

Comments
 (0)