Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion task-1/book.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
const bookName = "The fundamentals of JavaScript";

function isBookApplicable(searchString) {
// Your code here
const cleanSearch = searchString.trim().toLowerCase();
const cleanBook = bookName.toLowerCase();

const containWord = cleanBook.includes(cleanSearch);
return containWord;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You created clear variables with easy to read logics, well done!

But what if I provide an empty string? Or what if I call the isBookApplicable function without a parameter?

console.log(isBookApplicable(""));
console.log(isBookApplicable());

That's why, in software engineering, it's very important to first consider all the requirements and error cases that need to be handled ("Error Handling").

}
38 changes: 37 additions & 1 deletion task-2/parse-date.js
Original file line number Diff line number Diff line change
@@ -1 +1,37 @@
// Your code here
function parseDateString(dateString) {
const format = dateString.slice(0, 3); // "MDY" або "DMY"
const datePart = dateString.slice(4); // "10-21-1983"

const first = Number(datePart.slice(0, 2));
const second = Number(datePart.slice(3, 5));
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variable names first and second are not clear enough. It would be hard for future developers to tell what is first and what is second at first glance.

const year = Number(datePart.slice(6, 10));

let day;
let month;

if (format === "MDY") {
month = first;
day = second;
} else if (format === "DMY") {
day = first;
month = second;
} else {
console.log("Wrong format. Use MDY or DMY");
return null;
}

return { day, month, year };
}


console.log(parseDateString("MDY 10-21-1983"));
// Output: { day: 21, month: 10, year: 1983 }

console.log(parseDateString("DMY 21-10-1983"));
// Output: { day: 21, month: 10, year: 1983 }

console.log(parseDateString("MDY 03-15-2024"));
// Output: { day: 15, month: 3, year: 2024 }

console.log(parseDateString("DMY 15-03-2024"));
// Output: { day: 15, month: 3, year: 2024 }
33 changes: 33 additions & 0 deletions task-3/date.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@


// convertHoursToMinutes,
// convertMinutesToHours,
// convertDaysToHours,
// convertHoursToDays,
// convertMinutesToSeconds,
// convertSecondsToMinutes
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please try to avoid using excessive comments.



export function convertHoursToMinutes(hours){
return hours * 60;
}

export function convertMinutesToHours(minutes){
return minutes / 60;
}

export function convertDaysToHours(days) {
return days * 24;
}

export function convertHoursToDays(hours) {
return hours / 24;
}

export function convertMinutesToSeconds(minutes) {
return minutes * 60;
}

export function convertSecondsToMinutes(seconds) {
return seconds / 60;
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You implemented all the requirements, well done!

54 changes: 53 additions & 1 deletion task-4/cleanup.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,56 @@ console.log("Wind chill in " + cityName2 + ": " + windChill2.toFixed(2) + "°C")
// Wind chill calculation for City 3
let windSpeed3 = 25;
let windChill3 = 13.12 + 0.6215 * tempCelsius3 - 11.37 * Math.pow(windSpeed3, 0.16) + 0.3965 * tempCelsius3 * Math.pow(windSpeed3, 0.16);
console.log("Wind chill in " + cityName3 + ": " + windChill3.toFixed(2) + "°C");
console.log("Wind chill in " + cityName3 + ": " + windChill3.toFixed(2) + "°C");




//DRY

function cityName(name) {
return `Weather Report for ${name}`;
}

function getStatusCelsius(celsius) {
if (celsius < 0) return "Status: Freezing";
if (celsius < 10) return "Status: Cold";
if (celsius < 20) return "Status: Mild";
if (celsius < 30) return "Status: Warm";
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice refactoring of status logic 👏

return "Status: Hot";
}

function getStatusFahrenheit(celsius) {
return (celsius * 9 / 5) + 32;
}

function getStatusKelvin(celsius) {
return celsius + 273.15;
}

function calculateWindChill(tempCelsius, windSpeed) {
const windSpeedPower = Math.pow(windSpeed, 0.16);

const windChill =
13.12 +
0.6215 * tempCelsius -
11.37 * windSpeedPower +
0.3965 * tempCelsius * windSpeedPower;

return windChill;
}

function printWindChill(city, tempCelsius, windSpeed) {
const windChill = calculateWindChill(tempCelsius, windSpeed);
console.log(`Wind chill in ${city}: ${windChill.toFixed(2)}°C`);
}

function printWeatherReport(cityNameValue, celsius, windSpeed) {
console.log(cityName(cityNameValue));
console.log(`Temperature: ${celsius}°C`);
console.log(`Temperature: ${getStatusFahrenheit(celsius)}°F`);
console.log(`Temperature: ${getStatusKelvin(celsius)}K`);
console.log(getStatusCelsius(celsius));
printWindChill(cityNameValue, celsius, windSpeed);
console.log("---");
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your refactoring is incomplete. You also need to call the printWeatherReport with parameters. Did you manage to run this code? Because when you run, you should have seen that there are some errors that you need to resolve. But you're almost there. And keep in mind that when you run your logic, the output should be the same as the original file.