@@ -16,9 +16,9 @@ console.log(`The percentage change is ${percentageChange}`);
1616// These function calls are Number, replaceAll, and console.log
1717
1818// b) Run the code and identify the line where the error is coming from - why is this error occurring? How can you fix this problem?
19- // The error is from line 5:
20- // priceAfterOneYear = Number(priceAfterOneYear.replaceAll( "," ""));
21- // There should be a comma to separate arguments
19+ // The error originally came from the replaceAll call for priceAfterOneYear: the two arguments
20+ // ( ",", "") were missing a comma between them, causing a SyntaxError.
21+ // The fix was adding the missing comma so replaceAll(",", "") has two properly separated arguments.
2222
2323// c) Identify all the lines that are variable reassignment statements
2424// Variable reassignment statements on lines 4 and 5.
@@ -30,4 +30,5 @@ console.log(`The percentage change is ${percentageChange}`);
3030// On lines 7 and 8, variables priceDifference and percentageChange are declared by const.
3131
3232// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression?
33- // To remove comma as a punctuation and space such that the string is ready turn into a number by method Number.
33+ // replaceAll(",", "") removes all comma characters from the string, since commas aren't valid in a numeric value.
34+ // Number() then converts the resulting clean string into an actual number, so it can be used in arithmetic.
0 commit comments