Skip to content

Commit 9f2e8ac

Browse files
committed
Completed section 3
1 parent 9243056 commit 9f2e8ac

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

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

Lines changed: 9 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,19 @@ 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+
// 5 functions calls. They are on lines, 4, 5, and 10
1516

1617
// 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?
18+
// There was a comma missing in line 5 in replaceAll("," ""). This was needed because replaceAll is a
19+
// function that takes two arguments. The missing comma caused a syntax error.
1720

1821
// c) Identify all the lines that are variable reassignment statements
22+
// Lines 4 and 5 are variable reassignment statements where carPrice and priceAfterOneYear are
23+
// reassigned new values.
1924

2025
// d) Identify all the lines that are variable declarations
26+
// Lines 1, 2, 7 and 8 are variable declarations where carPrice and priceAfterOneYear are declared.
2127

2228
// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression?
29+
// Number(carPrice.replaceAll(",", "")) removes all commas from the string carPrice and then converts it to a
30+
// number.

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,21 @@ 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+
// 6 variable declarations.
1516

1617
// b) How many function calls are there?
18+
// 0 function calls.
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 returns the remainder left over when movieLength is divided by 60. In this case.
2023

2124
// d) Interpret line 4, what does the expression assigned to totalMinutes mean?
25+
// The expression on line 4 calculates the length of the movie in minutes.
2226

2327
// e) What do you think the variable result represents? Can you think of a better name for this variable?
28+
// Result represents the movie length formatted as hours:minutes:seconds. A better name could be
29+
// formattedMovieLength.
2430

2531
// f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer
32+
// As long as movieLength is a non-negative integer representing seconds, the code will work.

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
// 3. creates a new string by removing the last character ('p') from penceString
29+
// 8. ensures the pence amount has at least three digits by adding zeros in front if needed
30+
// 9. takes the first character of the string which represents the pound
31+
// 14. takes the last two characters of the string which represent the pence
32+
// 18. outputs the formatted price in pounds and pence to the console

0 commit comments

Comments
 (0)