Skip to content

Commit aae8c5e

Browse files
author
lintsang
committed
corrected all defects
1 parent e6f6333 commit aae8c5e

3 files changed

Lines changed: 54 additions & 10 deletions

File tree

Sprint-2/3-mandatory-implement/1-bmi.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@
1515
// It should return their Body Mass Index to 1 decimal place
1616

1717
function calculateBMI(weight, height) {
18-
return (weight / height**2).toFixed(1);
18+
return Number((weight / height**2).toFixed(1));
1919
}

Sprint-2/3-mandatory-implement/2-cases.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
// Use the MDN string documentation to help you find a solution
1616
// This might help https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/toUpperCase
1717

18-
function UPPER_SNAKE_CASE(string){
19-
upperString = string.toUpperCase();
18+
function upperSnakeCase(string){
19+
const upperString = string.toUpperCase();
2020
return upperString.replaceAll(' ','_');
2121
}

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

Lines changed: 51 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,21 @@
33
// Your task is to write tests for as many different groups of input data or edge cases as you can, and fix any bugs you find.
44
function pad(num) {
55
let numString = num.toString();
6-
while (numString.length < 2) {
6+
if (numString.length < 2) {
77
numString = "0" + numString;
88
}
99
return numString;
1010
}
1111

1212
function formatAs12HourClock(time) {
1313
const hours = Number(time.slice(0, 2));
14-
const minute = pad(Number(time.slice(3,5)));
14+
const minute = time.slice(3,5);
1515
if (hours > 12) {
16-
return `${hours - 12}:${minute} pm`;
17-
} else if (hours == 12 & minute == '00'){
18-
return `${time} pm`;
16+
return `${pad(hours - 12)}:${minute} pm`;
17+
} else if (hours == 12){
18+
return `12:${minute} pm`;
19+
} else if (hours == 00){
20+
return `12:${minute} am`;
1921
}
2022
return `${time} am`;
2123
}
@@ -49,7 +51,7 @@ console.assert(
4951
);
5052

5153
const currentOutput5 = formatAs12HourClock("00:00");
52-
const targetOutput5 = "00:00 am";
54+
const targetOutput5 = "12:00 am";
5355
console.assert(
5456
currentOutput5 === targetOutput5,
5557
`current output: ${currentOutput5}, target output: ${targetOutput5}`
@@ -60,4 +62,46 @@ const targetOutput6 = "12:00 pm";
6062
console.assert(
6163
currentOutput6 === targetOutput6,
6264
`current output: ${currentOutput6}, target output: ${targetOutput6}`
63-
);
65+
);
66+
67+
const currentOutput7 = formatAs12HourClock("15:25");
68+
const targetOutput7 = "03:25 pm";
69+
console.assert(
70+
currentOutput7 === targetOutput7,
71+
`current output: ${currentOutput7}, target output: ${targetOutput7}`
72+
);
73+
74+
const currentOutput8 = formatAs12HourClock("00:08");
75+
const targetOutput8 = "12:08 am";
76+
console.assert(
77+
currentOutput8 === targetOutput8,
78+
`current output: ${currentOutput8}, target output: ${targetOutput8}`
79+
);
80+
81+
const currentOutput9 = formatAs12HourClock("08:35");
82+
const targetOutput9 = "08:35 am";
83+
console.assert(
84+
currentOutput9 === targetOutput9,
85+
`current output: ${currentOutput9}, target output: ${targetOutput9}`
86+
);
87+
88+
const currentOutput10 = formatAs12HourClock("20:35");
89+
const targetOutput10 = "08:35 pm";
90+
console.assert(
91+
currentOutput10 === targetOutput10,
92+
`current output: ${currentOutput10}, target output: ${targetOutput10}`
93+
);
94+
95+
const currentOutput11 = formatAs12HourClock("12:34");
96+
const targetOutput11 = "12:34 pm";
97+
console.assert(
98+
currentOutput11 === targetOutput11,
99+
`current output: ${currentOutput11}, target output: ${targetOutput11}`
100+
);
101+
102+
const currentOutput12 = formatAs12HourClock("00:34");
103+
const targetOutput12 = "12:34 am";
104+
console.assert(
105+
currentOutput12 === targetOutput12,
106+
`current output: ${currentOutput12}, target output: ${targetOutput12}`
107+
);

0 commit comments

Comments
 (0)