Skip to content

Commit b9af102

Browse files
author
Arthur
committed
Substring range and point
1 parent b5540b5 commit b9af102

3 files changed

Lines changed: 55 additions & 3 deletions

File tree

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

Lines changed: 24 additions & 2 deletions
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,33 @@ 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 4 function calls here. There are two when you use Number();
16+
The other call is about console.log() to print the string out.
17+
When you call the variable (priceDifference/ carPrice), it is a function call.
18+
The last one is
1519

1620
// 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?
1721

22+
It shows that I miss a ) parenthesis.
23+
24+
1825
// c) Identify all the lines that are variable reassignment statements
1926

27+
carPrice = Number(carPrice.replaceAll(",", ""));
28+
priceAfterOneYear = Number(priceAfterOneYear.replaceAll("," ""));
29+
2030
// d) Identify all the lines that are variable declarations
2131

22-
// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression?
32+
let carPrice = "10,000";
33+
let priceAfterOneYear = "8,543";
34+
35+
const priceDifference = carPrice - priceAfterOneYear;
36+
const percentageChange = (priceDifference / carPrice) * 100;
37+
38+
// e) Describe what is the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression?
39+
40+
It deletes all the comma insides.I
41+
The Number helps convert that string into an actual figure.
42+
43+
44+

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,31 @@ 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+
Six, the const with the functions inside.
16+
1517

1618
// b) How many function calls are there?
19+
4
1720

1821
// c) Using documentation, explain what the expression movieLength % 60 represents
1922
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators
2023

24+
It is called the remaining function, because if you use this function , you will use the remainingMinutes to divides 60 and get the remaining value .
25+
26+
2127
// d) Interpret line 4, what does the expression assigned to totalMinutes mean?
28+
It calls the variable movieLength and remainingSeconds and substract together and divide it 60.
29+
30+
2231

2332
// e) What do you think the variable result represents? Can you think of a better name for this variable?
33+
I think it represents the total hour , remaining minutes and the remaining seconds .Duration is a better name
34+
35+
2436

2537
// f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer
38+
yes
39+
I tried to put 6(second), 60(1 minute), 3600(equivalent to 1 hour)
40+
41+
42+

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

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,17 @@ console.log(`£${pounds}.${pence}`);
2424
// Try and describe the purpose / rationale behind each step
2525

2626
// To begin, we can start with
27-
// 1. const penceString = "399p": initialises a string variable with the value "399p"
27+
28+
line 1. const penceString = "399p": initialises a string variable with the value "399p"
29+
line 3. You define a penceStringWithoutTrailingP variable and call a function to cut a line, you use penceString.length -1 because
30+
you want to cut the p.
31+
32+
line 8: You define a variable paddedPenceNumberString and call a function to add 0 into the letters, if the words are not three characters long.
33+
line 9: You want to take the pound out of 399, so you call the function substring and only wants before the index 1, which is calculated by (0 , length -2);
34+
35+
line 14: You call a variable function and you subtract the value from index 1 to the end.
36+
line 18: print the variable pound and the variable pence with the .
37+
38+
39+
40+

0 commit comments

Comments
 (0)