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
22 changes: 20 additions & 2 deletions task-1/book.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
function isBookApplicable(searchString) {
// Your code here
function isBookApplicable(searchString) {
const titleOfbook ="The fundamentals of JavaScript";

const titleLowerCase = titleOfbook.toLowerCase();
return titleLowerCase.includes(searchString.trim().toLowerCase());
Copy link

Choose a reason for hiding this comment

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

It is good that you created a variable named titleLowerCase and assigned the logic to it. You could do the same for the search string. It is good practice to break logic into small chunks and assign them to variables so the code is more readable and easier for future developers to maintain. For example:

const normalizedBookTitle = bookTitle.toLowerCase();
const normalizedSearchString = searchString.trim().toLowerCase();

return normalizedBookTitle.includes(normalizedSearchString);

Also, what if I provide an empty string? Or what if I call the isBookApplicable function without a parameter? Or what if the search string has an extra space between words?

console.log(isBookApplicable(""));
console.log(isBookApplicable());
console.log(isBookApplicable("The fundamentals of                     JavaScript"));

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").

}

console.log(isBookApplicable("javascript"));
// Output: true

console.log(isBookApplicable("javascript "));
// Output: true

console.log(isBookApplicable("python"));
// Output: false

console.log(isBookApplicable("JavaScript"));
// Output: true

console.log(isBookApplicable("JAVASCRIPT"));
// Output: true
30 changes: 30 additions & 0 deletions task-2/parse-date.js
Original file line number Diff line number Diff line change
@@ -1 +1,31 @@
// Your code here
function parseDateString(dateString) {
//const format_MDY = "MDY 10-21-1983";
//const format_DMY = "DMY 21-10-1983";
if (dateString.includes("MDY")) {
const parts = dateString.split(" ")[1].split("-");
//Format: MM-DD-YYYY
const month = parts[0];
const day = parts[1];
const year = parts[2];
return { day, month, year };
} else if (dateString.includes("DMY")) {
//Format: DD-MM-YYYY
const parts = dateString.split(" ")[1].split("-");
Copy link

Choose a reason for hiding this comment

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

Please pay attention to the DRY principle.

const month = parts[1];
const day = parts[0];
const year = parts[2];
return { day, month, year };
Copy link

Choose a reason for hiding this comment

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

Nice that you handled all the requirements except returning values as numbers.

}
}
console.log(parseDateString("MDY 10-1-1983"));
// Output: { day: 1, 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 }
18 changes: 18 additions & 0 deletions task-3/date.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
export function convertHoursToMinutes(h){
return h * 60;
}
export function convertMinutesToHours(m){
return m / 60;
}
export function convertDaysToHours(d){
return d * 24;
}
export function convertHoursToDays(h){
return h / 24;
}
export function convertMinutesToSeconds(m){
return m * 60;
}
export function convertSecondsToMinutes(s){
return s / 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. One improvement would be to make your parameter names clearer. Please try to avoid using single letters for naming while programming. It might be hard for future developers to understand the code. Try to use clear naming.

107 changes: 36 additions & 71 deletions task-4/cleanup.js
Original file line number Diff line number Diff line change
@@ -1,80 +1,45 @@
// Temperature conversion and weather report for City 1
// Temperature conversion and weather report for City 1 and 2 and 3.
let cityName1 = "Amsterdam";
let tempCelsius1 = 22;
let tempFahrenheit1 = (tempCelsius1 * 9 / 5) + 32;
let tempKelvin1 = tempCelsius1 + 273.15;
console.log("Weather Report for " + cityName1);
console.log("Temperature: " + tempCelsius1 + "°C");
console.log("Temperature: " + tempFahrenheit1 + "°F");
console.log("Temperature: " + tempKelvin1 + "K");
if (tempCelsius1 < 0) {
console.log("Status: Freezing");
} else if (tempCelsius1 >= 0 && tempCelsius1 < 10) {
console.log("Status: Cold");
} else if (tempCelsius1 >= 10 && tempCelsius1 < 20) {
console.log("Status: Mild");
} else if (tempCelsius1 >= 20 && tempCelsius1 < 30) {
console.log("Status: Warm");
} else {
console.log("Status: Hot");
}
console.log("---");

// Temperature conversion and weather report for City 2
let windSpeed1 = 15;
let cityName2 = "Berlin";
let tempCelsius2 = 15;
let tempFahrenheit2 = (tempCelsius2 * 9 / 5) + 32;
let tempKelvin2 = tempCelsius2 + 273.15;
console.log("Weather Report for " + cityName2);
console.log("Temperature: " + tempCelsius2 + "°C");
console.log("Temperature: " + tempFahrenheit2 + "°F");
console.log("Temperature: " + tempKelvin2 + "K");
if (tempCelsius2 < 0) {
console.log("Status: Freezing");
} else if (tempCelsius2 >= 0 && tempCelsius2 < 10) {
console.log("Status: Cold");
} else if (tempCelsius2 >= 10 && tempCelsius2 < 20) {
console.log("Status: Mild");
} else if (tempCelsius2 >= 20 && tempCelsius2 < 30) {
console.log("Status: Warm");
} else {
console.log("Status: Hot");
}
console.log("---");

// Temperature conversion and weather report for City 3
let windSpeed2 = 20;
let cityName3 = "Copenhagen";
let tempCelsius3 = -5;
let tempFahrenheit3 = (tempCelsius3 * 9 / 5) + 32;
let tempKelvin3 = tempCelsius3 + 273.15;
console.log("Weather Report for " + cityName3);
console.log("Temperature: " + tempCelsius3 + "°C");
console.log("Temperature: " + tempFahrenheit3 + "°F");
console.log("Temperature: " + tempKelvin3 + "K");
if (tempCelsius3 < 0) {
console.log("Status: Freezing");
} else if (tempCelsius3 >= 0 && tempCelsius3 < 10) {
console.log("Status: Cold");
} else if (tempCelsius3 >= 10 && tempCelsius3 < 20) {
console.log("Status: Mild");
} else if (tempCelsius3 >= 20 && tempCelsius3 < 30) {
console.log("Status: Warm");
let windSpeed3 = 25;
function tempFahrenheit(tempCelsius){
return (tempCelsius * 9 / 5) + 32;
}
function tempKelvin(tempCelsius){
return tempCelsius + 273.15;
}
function weatherCondition(tempCelsius){
if (tempCelsius < 0) {
return "Freezing";
} else if (tempCelsius >= 0 && tempCelsius < 10) {
return "Cold";
} else if (tempCelsius >= 10 && tempCelsius < 20) {
return "Mild";
} else if (tempCelsius >= 20 && tempCelsius < 30) {
return "Warm";
} else {
console.log("Status: Hot");
return "Hot";
}}
function windChill(tempCelsius, windSpeed){
return 13.12 + 0.6215 * tempCelsius - 11.37 * Math.pow(windSpeed, 0.16) + 0.3965 * tempCelsius * Math.pow(windSpeed, 0.16);
}
function weatherReport(cityName, tempCelsius, windSpeed) {
console.log("Weather Report for " + cityName);
console.log("Temperature: " + tempCelsius + "°C");
console.log("Temperature: " + tempFahrenheit(tempCelsius) + "°F");
console.log("Temperature: " + tempKelvin(tempCelsius) + "K");
console.log("Status: " + weatherCondition(tempCelsius));
console.log("Wind chill in " + cityName + ": " + windChill(tempCelsius, windSpeed).toFixed(2) + "°C");
console.log("---");
}
weatherReport(cityName1, tempCelsius1, windSpeed1);
console.log("---");

// Wind chill calculation for City 1
let windSpeed1 = 15;
let windChill1 = 13.12 + 0.6215 * tempCelsius1 - 11.37 * Math.pow(windSpeed1, 0.16) + 0.3965 * tempCelsius1 * Math.pow(windSpeed1, 0.16);
console.log("Wind chill in " + cityName1 + ": " + windChill1.toFixed(2) + "°C");

// Wind chill calculation for City 2
let windSpeed2 = 20;
let windChill2 = 13.12 + 0.6215 * tempCelsius2 - 11.37 * Math.pow(windSpeed2, 0.16) + 0.3965 * tempCelsius2 * Math.pow(windSpeed2, 0.16);
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");
weatherReport(cityName2, tempCelsius2, windSpeed2);
console.log("---");
weatherReport(cityName3, tempCelsius3, windSpeed3);
Copy link

Choose a reason for hiding this comment

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

You used clear variable names and clear function names. And you implemented reusable functions in accordance with the separation of concerns principle; each function is responsible for one thing. Well done!

Your logic is correct; however, the outputs of your functions do not match the original file.