File tree Expand file tree Collapse file tree
Sprint-2/3-mandatory-interpret Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -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,10 @@ 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)There are 5 function calls on line 4, 5 and 10.
25+ //b) error is coming from line 5, there is missing , between arguments in replaceAll method
26+ //c) line 4 and 5
27+ //d) line 1,2 and 7,8
28+ /*e) replaceAll method inside of () replace comma with nothing, removing it from the string,
29+ then Number converts string to number data type */
Original file line number Diff line number Diff line change 1- const movieLength = 8784 ; // length of movie in seconds
1+ const movieLength = - 8784.08 ; // length of movie in seconds
22
33const remainingSeconds = movieLength % 60 ;
44const totalMinutes = ( movieLength - remainingSeconds ) / 60 ;
@@ -23,3 +23,11 @@ console.log(result);
2323// e) What do you think the variable result represents? Can you think of a better name for this variable?
2424
2525// f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer
26+
27+
28+ //a) There are 6 variable declarations.
29+ //b)There is 1 function call on line 10
30+ //c) movieLength use remainder operator % . movieLength % 60 returns the remaining seconds after dividing the movie length into full minutes.
31+ //d) expression assigned to totalMinutes calculate movie time in whole minutes.
32+ //e) This variable represent total movie time in hh/mm/ss format, we could name it totalTime or totalMovieTime.
33+ //f) Yes, the code works correctly when movieLength is non-negative whole number that represents seconds.
Original file line number Diff line number Diff line change @@ -24,4 +24,18 @@ console.log(`£${pounds}.${pence}`);
2424// Try and describe the purpose / rationale behind each step
2525
2626// To begin, we can start with
27+
2728// 1. const penceString = "399p": initialises a string variable with the value "399p"
29+ // 3. penceStringWithoutTrailingP is created using substring() on penceString. The purpose is to remove the trailing "p"..
30+ // 4. value for substring method to start from which is beginning of the string.
31+ // 5. penceString variable uses argument of .length to -1 (p) from the value, 399p becomes 399.
32+ // 6. substring method closure
33+ // 8. paddedPenceNumberString uses padStart() to make the string at least 3 characters long, adding "0" at the beginning when needed.
34+ // 9. pounds variable assigns paddedPenceNumberString that uses substring method which returns part of the string from the start of index.
35+ //10. value for substring method which is beginning of the string.
36+ //11. paddedPenceNumberString variable is using length argument and deduct 2 out of length of the string 399 become 3 as pounds.
37+ //12. Closes the substring method.
38+ //14. pence variable created from paddedPenceNumberString
39+ //15. substring method called which value of is in the parenthesis (variable length -2 characters)
40+ //16. method padEnd is called that contains at least 2 character and adds 0 at the end if needed.
41+ //18. we log £3.99 in the console.
You can’t perform that action at this time.
0 commit comments