Skip to content

Commit b619d91

Browse files
committed
Implement 12-hour clock formatting function and add test cases
1 parent ea0fca9 commit b619d91

File tree

2 files changed

+39
-5
lines changed

2 files changed

+39
-5
lines changed

Sprint-2/1-key-errors/0.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
11
// Predict and explain first...
2-
// =============> write your prediction here
2+
// =============> this function get the argument and as string then first letter in capital and the rest of string in lower case;
33

44
// call the function capitalise with a string input
55
// interpret the error message and figure out why an error is occurring
66

7-
function capitalise(str) {
8-
let str = `${str[0].toUpperCase()}${str.slice(1)}`;
9-
return str;
10-
}
7+
// function capitalise(str) {
8+
// let str = `${str[0].toUpperCase()}${str.slice(1)}`;
9+
// return str;
10+
// }
1111

1212
// =============> write your explanation here
13+
// the problem is in line 8, because we can not use the "str" twice, currently once we used as parameter and again as variable,
1314
// =============> write your new code here
15+
16+
function capitalise(str) {
17+
return `${str[0].toUpperCase()}${str.slice(1)}`;
18+
19+
}
20+
console.log(capitalise("hello world"));

Sprint-2/Prep/12hours.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
function formatAs12HourClock(time) {
2+
if (Number(time.slice(0, 2)) > 12) {
3+
return `${Number(time.slice(0, 2)) - 12}:00 pm`;
4+
}
5+
return `${time} am`;
6+
}
7+
8+
const currentOutput = formatAs12HourClock("08:00");
9+
const targetOutput = "08:00 am";
10+
console.assert(
11+
currentOutput === targetOutput,
12+
`current output: ${currentOutput}, target output: ${targetOutput}`
13+
);
14+
15+
const currentOutput2 = formatAs12HourClock("23:00");
16+
const targetOutput2 = "11:00 pm";
17+
console.assert(
18+
currentOutput2 === targetOutput2,
19+
`current output: ${currentOutput2}, target output: ${targetOutput2}`
20+
);
21+
const currentOutput3 = formatAs12HourClock("00:00");
22+
const targetOutput3 = "12:00 am";
23+
console.assert(
24+
currentOutput2 === targetOutput2,
25+
`current output: ${currentOutput2}, target output: ${targetOutput2}`
26+
);
27+
console.log(currentOutput3,targetOutput3);

0 commit comments

Comments
 (0)