Skip to content

Commit 6737ce4

Browse files
author
Diana Ausiejute
committed
Finished all 3 mandatory interpretation tasks
1 parent 624bb88 commit 6737ce4

3 files changed

Lines changed: 30 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)
Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const movieLength = 8784; // length of movie in seconds
1+
const movieLength = 2; // length of movie in seconds
22

33
const remainingSeconds = movieLength % 60;
44
const totalMinutes = (movieLength - remainingSeconds) / 60;
@@ -7,19 +7,25 @@ const remainingMinutes = totalMinutes % 60;
77
const totalHours = (totalMinutes - remainingMinutes) / 60;
88

99
const result = `${totalHours}:${remainingMinutes}:${remainingSeconds}`;
10-
console.log(result);
10+
console.log(result);
1111

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
28+
29+
30+
31+
console.log(result)

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,15 @@ 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.
36+
37+
38+

0 commit comments

Comments
 (0)