Skip to content

Commit 429bd8a

Browse files
committed
update to time format file
1 parent 4324216 commit 429bd8a

2 files changed

Lines changed: 17 additions & 12 deletions

File tree

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

Lines changed: 8 additions & 2 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 = -10; // length of movie in seconds
22

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

1617
// b) How many function calls are there?
17-
18+
// 2
1819
// c) Using documentation, explain what the expression movieLength % 60 represents
1920
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators
21+
// It means 60 % remainder of Movie length
2022

2123
// d) Interpret line 4, what does the expression assigned to totalMinutes mean?
24+
// totalMinutes is assigned a value of the result from (movieLength - remainingSeconds) / 60;
2225

2326
// e) What do you think the variable result represents? Can you think of a better name for this variable?
27+
// I think its the total movie length with a timer. Based on research it appears to be template literal variable as it mixes static text with dynamic data. Sorry I don't fully understand this bit yet
2428

2529
// f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer
30+
//any number greater than zero returns a valid positive hour, minute or seconds result. Changing the length to 0 returns 0:0:0. Any negative length returns negative values
31+
Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,13 @@
11
const penceString = "399p";
22

33
const penceStringWithoutTrailingP = penceString.substring(
4-
0,
5-
penceString.length - 1
6-
);
4+
0, penceString.length - 1);
75

86
const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0");
9-
const pounds = paddedPenceNumberString.substring(
10-
0,
11-
paddedPenceNumberString.length - 2
12-
);
7+
const pounds = paddedPenceNumberString.substring(0, paddedPenceNumberString.length - 2);
138

14-
const pence = paddedPenceNumberString
15-
.substring(paddedPenceNumberString.length - 2)
16-
.padEnd(2, "0");
9+
10+
const pence = paddedPenceNumberString.substring(paddedPenceNumberString.length - 2).padEnd(2, "0");
1711

1812
console.log(`£${pounds}.${pence}`);
1913

@@ -25,3 +19,8 @@ console.log(`£${pounds}.${pence}`);
2519

2620
// To begin, we can start with
2721
// 1. const penceString = "399p": initialises a string variable with the value "399p"
22+
// 2. const penceStringWithoutTrailingP = penceString.substring(0): sets penceStringWithoutTRailingP = 399.0 - penceString -1 = 39
23+
// 3. const paddedPenceNumberString - ensures the figure is 3 characters to taking us back to 399
24+
// 4 const pounds - removes 2 characters from the amount = 3
25+
// 5. const pence - adds the amount by 2 characters taking us back to either 39 or 99
26+
// 6. console displays the figures in pounds and pence = 3.99

0 commit comments

Comments
 (0)