Skip to content

Commit 8257fa0

Browse files
author
Payman IB
committed
sprint 1- mandatory-interpret 1 & 2 completed
1 parent 74687a6 commit 8257fa0

File tree

2 files changed

+27
-15
lines changed

2 files changed

+27
-15
lines changed

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,26 @@ console.log(result);
1313

1414
// a) How many variable declarations are there in this program?
1515

16+
6
17+
1618
// b) How many function calls are there?
1719

20+
5
21+
1822
// c) Using documentation, explain what the expression movieLength % 60 represents
1923
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators
2024

25+
// % is the remainder. that line of code divides the total seconds number by 60 and gives us the remaining seconds.
26+
2127
// d) Interpret line 4, what does the expression assigned to totalMinutes mean?
2228

29+
// in this line, totalMinutes of the move calculated. the remainder will be deducted and the rest of the second divided by 60 gives us the total minutes number.
30+
31+
2332
// e) What do you think the variable result represents? Can you think of a better name for this variable?
2433

34+
// it represents the move length in hour, minutes and seconds. and it would be better understood as duration.
35+
2536
// f) Try experimenting with different values of movieLength. Will this code work for all values of movieLength? Explain your answer
37+
38+
// yes as long as it receives the total seconds as a whole number it works fine.
Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,9 @@
11
const penceString = "399p";
2-
3-
const penceStringWithoutTrailingP = penceString.substring(
4-
0,
5-
penceString.length - 1
6-
);
7-
2+
const penceStringWithoutTrailingP = penceString.substring( 0, penceString.length - 1);
83
const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0");
9-
const pounds = paddedPenceNumberString.substring(
10-
0,
11-
paddedPenceNumberString.length - 2
12-
);
13-
14-
const pence = paddedPenceNumberString
15-
.substring(paddedPenceNumberString.length - 2)
16-
.padEnd(2, "0");
17-
4+
const pounds = paddedPenceNumberString.substring( 0 , paddedPenceNumberString.length - 2);
5+
const pence = paddedPenceNumberString.substring(paddedPenceNumberString.length - 2)
6+
.padEnd(2, "0");
187
console.log(${pounds}.${pence}`);
198

209
// This program takes a string representing a price in pence
@@ -25,3 +14,13 @@ console.log(`£${pounds}.${pence}`);
2514

2615
// To begin, we can start with
2716
// 1. const penceString = "399p": initialises a string variable with the value "399p"
17+
// 2. const penceStringWithoutTrailingP = penceString.substring( 0, penceString.length - 1): creates a new string with the last character removed by taking a substring from index 0 up to
18+
// penceString.length - 1, it removes the trailing "p" so we are left with the numeric pence portion as a string.
19+
// 3. const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0"): ensures the numeric string has at least 3 characters by adding leading zeros if required.
20+
// padStart(3, "0") will left-pad with "0" until the length is at least 3, so the code expects to split the string into ...pounds and last two digits = pence.
21+
// By guaranteeing at least 3 characters, the substring operations that follow always have at least one digit for pounds and two for pence.
22+
// 4. const pounds = paddedPenceNumberString.substring( 0 , paddedPenceNumberString.length - 2): takes the substring from the start up to the character two from the end.
23+
// That is, everything except the last two characters. as the last two characters represent pence; everything before that is pounds. Splitting this way converts a string of
24+
// pure pence into pounds and pence parts.
25+
// 5. substring(paddedPenceNumberString.length - 2): takes the last two characters (the pence portion).
26+
// 6. .padEnd(2, "0"): would add trailing zeros to make sure the pence string is at least 2 characters long.

0 commit comments

Comments
 (0)