Skip to content

Commit 6bc41e0

Browse files
committed
Update Sprint 2 code based on reviewer feedback
1 parent 66634e1 commit 6bc41e0

File tree

3 files changed

+40
-6
lines changed

3 files changed

+40
-6
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ console.log(decimalNumber);*/
2020
// =============> write your new code here
2121
function convertToPercentage(decimalNumber) {
2222
const percentage = `${decimalNumber * 100}%`;
23-
console.log(`Your Decimal number will be ${percentage}.`);
2423
return percentage;
2524
}
26-
convertToPercentage(0.9);
25+
console.log(convertToPercentage(0.9));
26+
27+
// I have removed the log inside the function, as we did not need to print that message each time we call the function.

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
function calculateBMI(weight, height) {
1818
let heightSquare = height * height;
1919
let bmi = weight / heightSquare;
20-
console.log(`Your BMI is ${bmi.toFixed(1)}`)
21-
return bmi;
20+
return bmi.toFixed(1);
2221
}
23-
calculateBMI(65, 1.73); // ==> 21.7
22+
console.log(calculateBMI(65, 1.73)); // ==> 21.7
23+
24+
// Thanks for mentioning the issue! Indeed its not a good idea to have the console.log() inside our function block.

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

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
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
// --- > Debugging this code was not easy for me, I could solve this by the help of AI Explaining each step and conditions and finally we made it work well with different inputs, I mean string with number character.
55

6-
function formatAs12HourClock(time) {
6+
/*function formatAs12HourClock(time) {
77
const hours = Number(time.slice(0, 2));
88
const minutes = time.slice(2);
99
@@ -27,7 +27,37 @@ function formatAs12HourClock(time) {
2727
} else {
2828
return `${formattedHours}${minutes} am`;
2929
}
30+
} */
31+
32+
function formatAs12HourClock(time) {
33+
let parts = time.split(":");
34+
let hours = Number(parts[0]);
35+
let minutes = parts[1];
36+
37+
let period = "am";
38+
if (hours >= 12) {
39+
period = "pm";
40+
}
41+
if (hours === 0) {
42+
hours = 12;
43+
} else if (hours >= 12) {
44+
hours = hours - 12;
45+
}
46+
if (hours < 10) {
47+
hours = "0" + hours;
48+
}
49+
if (typeof time !== "string" || !time.includes(":")) {
50+
return "Invalid input: please enter time in HH:MM format"
51+
} if (
52+
isNaN(hours) || hours < 0 || hours > 23
53+
|| isNaN(Number(minutes)) || Number(minutes) < 0
54+
|| Number(minutes) > 59
55+
) {
56+
return "Invalid input: hours must be 0-23 and minutes 0-59";
57+
}
58+
return `${hours}:${minutes} ${period}`;
3059
}
60+
console.log(formatAs12HourClock("19"));
3161

3262
const currentOutput = formatAs12HourClock("08:00");
3363
const targetOutput = "08:00 am";
@@ -47,3 +77,5 @@ console.assert(formatAs12HourClock("12:00") === "12:00 pm");
4777
console.assert(formatAs12HourClock("13:05") === "01:05 pm");
4878
console.assert(formatAs12HourClock("01:05") === "01:05 am");
4979
console.assert(formatAs12HourClock("23:59") === "11:59 pm");
80+
81+
// after receiving the feedback I wrote the function from scratch and at the end added an other condition to check the input for validation or correct input. if the user puts incorrect input then he will receive a message to correct his input.

0 commit comments

Comments
 (0)