Skip to content

Commit 97d3425

Browse files
committed
Sprint 1 - Step 3 mandatory interpret's all 3 tasks are done
1 parent 01932d2 commit 97d3425

3 files changed

Lines changed: 35 additions & 5 deletions

File tree

Sprint-1/3-mandatory-interpret/1-percentage-change.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ let carPrice = "10,000";
22
let priceAfterOneYear = "8,543";
33

44
carPrice = Number(carPrice.replaceAll(",", ""));
5-
priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," ""));
5+
priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",",""));
66

77
const priceDifference = carPrice - priceAfterOneYear;
88
const percentageChange = (priceDifference / carPrice) * 100;
@@ -12,11 +12,27 @@ 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+
// there are 5 function calls in this file. including methods used , 2 methods = replaceAll(), methods are called under their object, replaceAll() is called under the string object.
16+
// The lines where a function call is made are:
17+
// Line 4: carPrice.replaceAll(",", "")
18+
// Line 5: priceAfterOneYear.replaceAll(",", "")
19+
// Line 7: console.log(`The percentage change is ${percentageChange}`)
1520

1621
// 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?
22+
//syntaxError: missing ) after argument list, -
23+
//the error is occurring because of a missing "," in the replaceAll() method. in line 5.
1724

1825
// c) Identify all the lines that are variable reassignment statements
26+
// The lines that are variable reassignment statements are:
27+
// Line 4: carPrice = Number(carPrice.replaceAll(",", ""));
28+
// Line 5: priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," ""));
1929

2030
// d) Identify all the lines that are variable declarations
31+
// The lines that are variable declarations are:
32+
// Line 1: let carPrice = "10,000";
33+
// Line 2: let priceAfterOneYear = "8,543";
34+
// Line 7: const priceDifference = carPrice - priceAfterOneYear;
35+
// Line 8: const percentageChange = (priceDifference / carPrice) * 100;
2136

2237
// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression?
38+
// The expression Number(carPrice.replaceAll(",","")) is converting the string value of carPrice into a number by removing the comma from the string.

Sprint-1/3-mandatory-interpret/2-time-format.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,23 @@ console.log(result);
1212
// For the piece of code above, read the code and then answer the following questions
1313

1414
// a) How many variable declarations are there in this program?
15+
// there are 6 variable declarations in this program.
1516

1617
// b) How many function calls are there?
18+
// there is 1 function call in this program, which is the console.log().
1719

1820
// c) Using documentation, explain what the expression movieLength % 60 represents
1921
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators
22+
// The expression movieLength % 60 represents the remainder of the division of movieLength by 60.
23+
// In this case, it calculates the number of seconds remaining after converting the total movie length from seconds to minutes.
24+
// The modulo operator (%) returns the remainder of a division operation, so it helps to determine how many seconds are left after accounting for full minutes in the movie length.
25+
// this means 8784 seconds is exactly 146 minutes and 24 seconds.
2026

2127
// d) Interpret line 4, what does the expression assigned to totalMinutes mean?
28+
// The expression assigned to totalMinutes will return the total number of minutes only leaving the seconds out.
2229

2330
// e) What do you think the variable result represents? Can you think of a better name for this variable?
31+
// the variable holds the hour,minutes and seconds a movie is long, so i prefer to name it movieDuration.
2432

2533
// f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer
34+
// yes, this code will work for all values of movieLength because every attributes of the movieLength variable is being calculated and converted to hours, minutes and seconds.

Sprint-1/3-mandatory-interpret/3-to-pounds.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@ const penceString = "399p";
33
const penceStringWithoutTrailingP = penceString.substring(
44
0,
55
penceString.length - 1
6-
);
6+
); // remove the trailing "p" from the string
77

8-
const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0");
8+
const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"); // pad the string with leading zeros to ensure it has at least 3 characters
99
const pounds = paddedPenceNumberString.substring(
1010
0,
1111
paddedPenceNumberString.length - 2
12-
);
12+
); // get the substring representing the pounds by taking all characters except the last two
1313

1414
const pence = paddedPenceNumberString
1515
.substring(paddedPenceNumberString.length - 2)
16-
.padEnd(2, "0");
16+
.padEnd(2, "0"); // get the substring representing the pence by taking the last two characters and padding it with a "0" if necessary
1717

1818
console.log(${pounds}.${pence}`);
1919

@@ -25,3 +25,8 @@ console.log(`£${pounds}.${pence}`);
2525

2626
// To begin, we can start with
2727
// 1. const penceString = "399p": initialises a string variable with the value "399p"
28+
//2. const penceStringWithoutTrailingP = penceString.substring(0, penceString.length - 1): removes the trailing "p" from the string to get the numeric part of the price in pence
29+
//3. const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"): pads the string with leading zeros to ensure it has at least 3 characters, which is useful for prices less than £1
30+
//4. const pounds = paddedPenceNumberString.substring(0, paddedPenceNumberString.length - 2): extracts the substring representing the pounds by taking all characters/values except the last two
31+
//5. const pence = paddedPenceNumberString.substring(paddedPenceNumberString.length - 2).padEnd(2, "0"): extracts the substring representing the pence by taking the last two characters and padding it with a "0" if necessary
32+
//6. console.log(`£${pounds}.${pence}`): outputs the final formatted price in pounds and pence to the console

0 commit comments

Comments
 (0)