Skip to content

Commit 3d91901

Browse files
committed
fixed my explanation of the code on the use of const and let
1 parent 6e0c311 commit 3d91901

1 file changed

Lines changed: 7 additions & 6 deletions

File tree

  • Sprint-2/1-key-errors

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22

33
// Why will an error occur when this program runs?
44
// =============> write your prediction here
5-
/* - The function will throw a syntax error because we have redeclared the parameter variable "decimalNumber", and we have
6-
also used const for declaring percentage, percentage will change when we call the function with different arguments so it should
7-
be declared using let.
5+
/* - The function will throw a syntax error because we have redeclared the parameter variable "decimalNumber".
86
- we are console logging the variable decimalNumber outside the function - the variable lives only inside the function
97
*/
108

@@ -21,10 +19,13 @@
2119

2220
// =============> write your explanation here
2321
/*I will remove line 14 - a redeclaration of the parameter variable, we will not reassign it, we will get the decimal
24-
number by calling the function with an argument and we will console.log the function call*/
22+
number by calling the function with an argument, and we will console.log the function call*/
2523
// Finally, correct the code to fix the problem
2624
// =============> write your new code here
27-
function convertToPercentage(decimalNumber){
28-
return `${decimalNumber * 100}%`;
25+
function convertToPercentage(decimalNumber) {
26+
decimalNumber = 0.5;
27+
const percentage = `${decimalNumber * 100}%`;
28+
return percentage;
2929
}
30+
3031
console.log(convertToPercentage(0.5))

0 commit comments

Comments
 (0)