Skip to content

Commit e18f838

Browse files
committed
Completed mandatory interpretation tasks in the folder 3
1 parent 9977d32 commit e18f838

3 files changed

Lines changed: 25 additions & 12 deletions

File tree

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

Lines changed: 6 additions & 5 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,12 @@ 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-
15+
// 4, 5, 8
1616
// 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-
17+
// It was a syntax error, it can be fixed by adding the missing part (1 of 2 parentheses)
1818
// c) Identify all the lines that are variable reassignment statements
19-
19+
// 4, 5
2020
// d) Identify all the lines that are variable declarations
21-
21+
// 1, 2
2222
// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression?
23+
// It turns/converts a string into a number by removing the comma and quotation marks (since they are non-number values)

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,18 @@ 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-
15+
// 6
1616
// b) How many function calls are there?
17-
17+
// 5
1818
// c) Using documentation, explain what the expression movieLength % 60 represents
1919
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators
20+
// The remainder operator calculates the remainder of movie in seconds (it does it by dividing the number by 60)
2021

2122
// d) Interpret line 4, what does the expression assigned to totalMinutes mean?
22-
23+
// total minutes (in seconds) - remaining seconds = remaining seconds. Then converts the seconds into minutes
2324
// e) What do you think the variable result represents? Can you think of a better name for this variable?
24-
25+
// It represents how much of the movie is left to watch. Maybe something like remainderOfTheMovie
2526
// f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer
27+
// It won't work with all values. Most importantly, the value must be strictly numeric and positive
28+
29+
console.log(result);

‎Sprint-2/3-mandatory-interpret/3-to-pounds.js‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ const penceString = "399p";
22

33
const penceStringWithoutTrailingP = penceString.substring(
44
0,
5-
penceString.length - 1
5+
penceString.length - 1,
66
);
77

88
const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0");
99
const pounds = paddedPenceNumberString.substring(
1010
0,
11-
paddedPenceNumberString.length - 2
11+
paddedPenceNumberString.length - 2,
1212
);
1313

1414
const pence = paddedPenceNumberString
@@ -24,4 +24,12 @@ 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+
// 1. const penceString = "399p": initializes a string variable with the value "399p"
28+
// 3-6. const penceStringWithoutTrailingP = penceString.substring(0, penceString.length - 1);
29+
// : initializes a variable, the value of which is turned to numerical by removing the letter "p".
30+
// 8. const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0");
31+
// Here the padstart function turns "399" string into 399 number (it could add some zeroes in front, but here it serves as a converter)
32+
// 9-12. const pounds = paddedPenceNumberString.substring(0, paddedPenceNumberString.length - 2);
33+
// Here the goal is to initialize a variable of Pounds (with the value of 3), by splitting it from 99, and it's done using the substring method
34+
// 14-16. const pence = paddedPenceNumberString.substring(paddedPenceNumberString.length - 2).padEnd(2, "0");
35+
// Here the pence variable is introduced with the value of 99 and it's done by taking the 399 and removing 3 using substring and padEnd methods.

0 commit comments

Comments
 (0)