Skip to content

Commit 4e6c099

Browse files
committed
Refactor toPounds function for clarity and return value; enhance time-format.js comments for accuracy; add additional test cases in format-time.js
1 parent aaf1fa0 commit 4e6c099

3 files changed

Lines changed: 36 additions & 16 deletions

File tree

Sprint-2/3-mandatory-implement/3-to-pounds.js

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,25 @@
66
// You should call this function a number of times to check it works for different inputs
77

88
function toPounds(penceString) {
9-
const penceStringWithoutTrailingP = penceString.substring(
10-
0,
11-
penceString.length - 1
12-
);
9+
const penceStringWithoutTrailingP = penceString.substring(
10+
0,
11+
penceString.length - 1
12+
);
1313

14-
const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0");
15-
const pounds = paddedPenceNumberString.substring(
16-
0,
17-
paddedPenceNumberString.length - 2
18-
);
14+
const paddedPenceNumberString = penceStringWithoutTrailingP.padStart(3, "0");
15+
const pounds = paddedPenceNumberString.substring(
16+
0,
17+
paddedPenceNumberString.length - 2
18+
);
1919

20-
const pence = paddedPenceNumberString
21-
.substring(paddedPenceNumberString.length - 2)
22-
.padEnd(2, "0");
20+
const pence = paddedPenceNumberString
21+
.substring(paddedPenceNumberString.length - 2)
22+
.padEnd(2, "0");
2323

24-
console.log(${pounds}.${pence}`);
24+
return ${pounds}.${pence}`;
25+
}
26+
27+
console.log(toPounds("1p"));
28+
console.log(toPounds("90p"));
29+
console.log(toPounds("303p"));
30+
console.log(toPounds("23456p"));

Sprint-2/4-mandatory-interpret/time-format.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@ function formatTimeDisplay(seconds) {
2121
// Questions
2222

2323
// a) When formatTimeDisplay is called how many times will pad be called?
24-
// =============> write your answer here
24+
// =============> 3
2525

2626
// Call formatTimeDisplay with an input of 61, now answer the following:
2727

2828
// b) What is the value assigned to num when pad is called for the first time?
29-
// =============> write your answer here
29+
// =============> 1
3030

3131
// c) What is the return value of pad is called for the first time?
32-
// =============> write your answer here
32+
// =============> "01"
3333

3434
// d) What is the value assigned to num when pad is called for the last time in this program? Explain your answer
3535
// =============> write your answer here

Sprint-2/5-stretch-extend/format-time.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,17 @@ console.assert(
2323
currentOutput2 === targetOutput2,
2424
`current output: ${currentOutput2}, target output: ${targetOutput2}`
2525
);
26+
27+
const currentOutput3 = formatAs12HourClock("13:15");
28+
const targetOutput3 = "1:15 pm";
29+
console.assert(
30+
currentOutput3 === targetOutput3,
31+
`current output: ${currentOutput3}, target output: ${targetOutput3}`
32+
);
33+
34+
const currentOutput4 = formatAs12HourClock("12:00");
35+
const targetOutput4 = "12:00 am";
36+
console.assert(
37+
currentOutput4 === targetOutput4,
38+
`current output: ${currentOutput4}, target output: ${targetOutput4}`
39+
);

0 commit comments

Comments
 (0)