Skip to content

Commit 063ef8d

Browse files
committed
fix error 1
1 parent cfa3c0e commit 063ef8d

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

  • Sprint-3/1-key-errors

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

Lines changed: 10 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+
// because the decimanlNumber variable has already been declared and you cant declare it twice, also the parameter needs to not be tied to any value so it works as intended
55

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

@@ -15,6 +15,14 @@ function convertToPercentage(decimalNumber) {
1515
console.log(decimalNumber);
1616

1717
// =============> write your explanation here
18+
// decimalNumber creates a variable in the function scope, then const decimalNumber tries to create a variable with the same name in that same scope, then it hits a Syntax error. Then the program stops running
1819

1920
// Finally, correct the code to fix the problem
20-
// =============> write your new code here
21+
22+
function convertToPercentage(decimalNumber) {
23+
const percentage = (`${decimalNumber * 100}%`);
24+
25+
return percentage;
26+
}
27+
28+
console.log(convertToPercentage(0.5));

0 commit comments

Comments
 (0)