@@ -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 ;
@@ -12,11 +12,24 @@ console.log(`The percentage change is ${percentageChange}`);
1212// Read the code and then answer the questions below
1313
1414// a) How many function calls are there in this file? Write down all the lines where a function call is made
15-
16- // 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?
17-
18- // c) Identify all the lines that are variable reassignment statements
19-
20- // d) Identify all the lines that are variable declarations
21-
22- // e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression?
15+ / * t h e r e h a s f i v e f u n c t i o n i n l i n e 4 a n d a n d c o n s o l e . l o g a l s o h a s o n e
16+ line 4 and 5 has two Number ( ) function
17+ line 4 and 5 has two replaceALL ( ) function
18+ line 10 has one console . log ( )
19+
20+ / * b ) R u n t h e c o d e a n d i d e n t i f y t h e l i n e w h e r e t h e e r r o r i s c o m i n g f r o m - w h y i s t h i s e r r o r o c c u r r i n g ? H o w c a n y o u f i x t h i s p r o b l e m ?
21+ In line five error shown in replaceAll ( "," "")); missing comma before last two comma(" , "," ") .
22+
23+ / * c ) I d e n t i f y a l l t h e l i n e s t h a t a r e v a r i a b l e r e a s s i g n m e n t s t a t e m e n t s
24+ line 4 carPrice = Number ( carPrice . replaceAll ( "," , "" ) ) ;
25+ line 5 priceAfterOneYear = Number ( priceAfterOneYear . replaceAll ( "," , "" ) ) ;
26+ As per the carPrice and priceAfterOneYear has been declared in line 1 and 2 by using let variable .
27+
28+ / * d ) I d e n t i f y a l l t h e l i n e s t h a t a r e v a r i a b l e d e c l a r a t i o n s
29+ line 1 let carPrice = "10,000" ;
30+ line 2 let priceAfterOneYear = "8,543" ;
31+ line 7 const priceDifference = carPrice - priceAfterOneYear ;
32+ line 8 const percentageChange = ( priceDifference / carPrice ) * 100 ;
33+
34+ / * e ) D e s c r i b e w h a t t h e e x p r e s s i o n N u m b e r ( c a r P r i c e .r e p l a c e A l l ( " , " , " " ) ) i s d o i n g - w h a t i s t h e p u r p o s e o f t h i s e x p r e s s i o n ?
35+ replaceALL throwout all the commas from the string and number became numerical value .
0 commit comments