@@ -2,7 +2,7 @@ let carPrice = "10,000";
22let priceAfterOneYear = "8,543" ;
33
44carPrice = Number ( carPrice . replaceAll ( "," , "" ) ) ;
5- priceAfterOneYear = Number ( priceAfterOneYear . replaceAll ( "," "" ) ) ;
5+ priceAfterOneYear = Number ( priceAfterOneYear . replaceAll ( "," , "" ) ) ;
66
77const priceDifference = carPrice - priceAfterOneYear ;
88const percentageChange = ( priceDifference / carPrice ) * 100 ;
@@ -20,3 +20,25 @@ console.log(`The percentage change is ${percentageChange}`);
2020// d) Identify all the lines that are variable declarations
2121
2222// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression?
23+
24+ // a) I found 5 places where the code "calls" a function (runs a built-in command):
25+ // Line 4: Number(...) and carPrice.replaceAll(...)
26+ // Line 5: Number(...) and priceAfterOneYear.replaceAll(...)
27+ // Line 10: console.log(...)
28+ //
29+ // b) The error showed up on Line 5. It said "SyntaxError: missing ) after
30+ // argument list". That just means I had one too many closing brackets ( ) )
31+ // at the end of that line.
32+ //
33+ // c) There are 2 lines where a variable gets a new value (reassignment):
34+ // Line 4: carPrice = ...
35+ // Line 5: priceAfterOneYear = ...
36+ //
37+ // d) There are 4 lines where a new variable is created (declaration):
38+ // Line 1, Line 2, Line 7, and Line 8.
39+ //
40+ // e) Number(carPrice.replaceAll(",", "")) does two things, step by step:
41+ // First, replaceAll(",", "") takes out all the commas from the text, so
42+ // "10,000" turns into "10000".
43+ // Then, Number(...) changes that text into a real number (10000), so we
44+ // can do maths with it instead of treating it like a word.
0 commit comments