Skip to content

Commit 571ed31

Browse files
committed
Revert "Work on 3-mandatory-interpret"
This reverts commit bb7ccaa.
1 parent 8d1d385 commit 571ed31

3 files changed

Lines changed: 2 additions & 22 deletions

File tree

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

Lines changed: 1 addition & 8 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,18 +12,11 @@ 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-
//
16-
// 3 function calls at lines:
17-
// 4, 5, 10
1815

1916
// 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?
20-
// Because there is a missing comma at line 5. By adding the missing comma
2117

2218
// c) Identify all the lines that are variable reassignment statements
23-
// 4, 5
2419

2520
// d) Identify all the lines that are variable declarations
26-
// 1, 2, 7, 8
2721

2822
// e) Describe what the expression Number(carPrice.replaceAll(",","")) is doing - what is the purpose of this expression?
29-
// it replaces all the occurances of "," to "" so essentially deleting commas so it can be turned into a number
Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const movieLength = 10000; // length of movie in seconds
1+
const movieLength = 8784; // length of movie in seconds
22

33
const remainingSeconds = movieLength % 60;
44
const totalMinutes = (movieLength - remainingSeconds) / 60;
@@ -12,21 +12,14 @@ 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
1615

1716
// b) How many function calls are there?
18-
// 1
1917

2018
// c) Using documentation, explain what the expression movieLength % 60 represents
2119
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators
22-
// it divides the number by 60 so we know how many seconds are remaining by using the modulo operator
2320

2421
// d) Interpret line 4, what does the expression assigned to totalMinutes mean?
25-
// this is to convert seconds into minutes without losing any seconds becuase we keep them in remainingSecondds
2622

2723
// e) What do you think the variable result represents? Can you think of a better name for this variable?
28-
// This represents how many hours, minutes and seconds left in the movie. formattedTime.
29-
//
3024

3125
// f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer
32-
// Yeah I think this will work for different inputs, becuase we are using modulo so we're not losing any seconds when dividing

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,20 @@
1-
// initialises a string variable with the value "399p"
21
const penceString = "399p";
32

4-
// This cuts the string so we're only saving everything before the p
53
const penceStringWithoutTrailingP = penceString.substring(
64
0,
75
penceString.length - 1
86
);
97

10-
// This adds zeros to the start of the string if the string's length is less than 3
118
const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0");
12-
// this only saves the string minus the two letters at the end.
139
const pounds = paddedPenceNumberString.substring(
1410
0,
1511
paddedPenceNumberString.length - 2
1612
);
1713

18-
// this extracts the last two characters and adds zeroes to the end
1914
const pence = paddedPenceNumberString
2015
.substring(paddedPenceNumberString.length - 2)
2116
.padEnd(2, "0");
2217

23-
// prints the result
2418
console.log(${pounds}.${pence}`);
2519

2620
// This program takes a string representing a price in pence

0 commit comments

Comments
 (0)