Skip to content

Commit 6ecd7a2

Browse files
committed
completed 3-mandatory-interpret-exercises
1 parent 5d732f2 commit 6ecd7a2

3 files changed

Lines changed: 21 additions & 10 deletions

File tree

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,16 @@ 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+
//answer: we have 5 function calls across 3 lines:
16+
//line 4
17+
//line 5
18+
//line 10
1619
// 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-
20+
//answer: on line 5, there is a typo, a replaceAll("," ""));
21+
//fix line 5 by changing it to priceAfterOneYear = Number(priceAfterOneYear.replaceAll(",", ""));
1822
// c) Identify all the lines that are variable reassignment statements
19-
23+
//answer: lines 4 and 5
2024
// d) Identify all the lines that are variable declarations
21-
25+
//answer: line 1, 2, 7 and 8
2226
// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression?
27+
//answer: .ReplaceAll(",", "") this will remove a comma from the price string and number will convert that clean string into a numeric value so mathematical calculations can be perfomed.

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,15 @@ 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+
//answer: we have 6 variable declarations
1616
// b) How many function calls are there?
17-
17+
//answer: there is 1 function call: line 10
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-
20+
//answer:% is a remainder operator, it calculates left over seconds when movie length is divided into full minutes
2121
// d) Interpret line 4, what does the expression assigned to totalMinutes mean?
22-
22+
//answer:it subtracts the left over seconds from the total movie length to get a multiple of 60, then divides by 60 to convert that duration into whole minutes.
2323
// e) What do you think the variable result represents? Can you think of a better name for this variable?
24-
24+
//answer: formatted movieLength, it represents the movieLength format as a time string
2525
// f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer
26+
//answer: yes it can work but only for positive numbers representing total seconds, if the movieLength is negative it will give off an output of an invalid time value

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,9 @@ 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": initialises a string variable with the value "399p" representing the price in pence including the trailing letter 'p'
28+
// 2. const penceStringWithoutTrailingP = penceString.substring(0, penceString.length - 1): Extract the numeric portion of the penceString by taking characters from index 0 up to the last character removing the 'p'
29+
// 3. const paddedPenceNumberString = penceStringWithoutTrailingP . padStart(3, "0"): it ensures the penceString is at least 3 digits long by adding leading zeros if necessary
30+
// 4. const pounds = paddedPenceNumberString.substring(0, paddedPenceNumberString.length - 2): Extracts the pounds portion of the price by taking all digits except the last 2
31+
// 5. const pence = paddedPenceNumberString.substring(paddedPenceNumberString.length - 2) padEnd(2, "0") it extracts the last 2 digits representing pence ensuring it is padded to 2 digits
32+
// 6. line 18 = formats and prints the final price string with the pound symbol, amount, period and pence amount

0 commit comments

Comments
 (0)