Skip to content

Commit 4b403bd

Browse files
committed
submitted completed task
1 parent a6c092d commit 4b403bd

File tree

1 file changed

+15
-1
lines changed
  • Sprint-2/1-key-errors

1 file changed

+15
-1
lines changed

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
// =============> write your prediction here
55

66
// Try playing computer with the example to work out what is going on
7-
7+
/*
88
function convertToPercentage(decimalNumber) {
99
const decimalNumber = 0.5;
1010
const percentage = `${decimalNumber * 100}%`;
@@ -13,8 +13,22 @@ function convertToPercentage(decimalNumber) {
1313
}
1414
1515
console.log(decimalNumber);
16+
*/
1617

1718
// =============> write your explanation here
19+
/*
20+
1. Undeclared variables are automatically declared when first used. As a parameter in the 'convertToPercentage' function,
21+
'decimalNumber' is (automatically) already declared. trying to declare it again with 'const' will cause a syntax error.
22+
2. Also, the 'console.log(decimalNumber);' line is outside the function, so 'decimalNumber' is not defined in that scope.
23+
3 decimalNumber = 0.5; overwrites the argument supplied, and so to make the function work as intended, this line should be removed, so the function does not ignore its input argument.
24+
*/
1825

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

0 commit comments

Comments
 (0)