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
17 changes: 16 additions & 1 deletion task-1/book.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
function isBookApplicable(searchString) {
// Your code here
if (!searchString) {
return false;
}
let cleanedSearch = searchString.trim().toLowerCase();

if (cleanedSearch === "") {
return false;
}
Comment on lines +2 to +9

Choose a reason for hiding this comment

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

 if (!searchString) {          
        return false;
    }

and

 if (cleanedSearch === "") {
        return false;
    }

Good job, just a small note: both of these are basically doing the same thing! The second one after the trim would be enough!


let bookTitle = "The fundamentals of JavaScript".toLowerCase();

Choose a reason for hiding this comment

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

This variable and the previous one are not reassigned, so const would be more appropriate than let.


let isFound = bookTitle.includes(cleanedSearch);


return isFound;
Comment on lines +13 to +16

Choose a reason for hiding this comment

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

Nice, this works! But as another option: the .includes() method already returns a boolean (true or false), so there is no need to store it in a variable before returning it.

You can simplify this:

let isFound = bookTitle.includes(cleanedSearch);
return isFound;

To

return bookTitle.includes(cleanedSearch);

}
console.log(isBookApplicable('python'));
39 changes: 38 additions & 1 deletion task-2/parse-date.js
Original file line number Diff line number Diff line change
@@ -1 +1,38 @@
// Your code here
function parseDateString(dateString) {
let parts = dateString.split(" ");

let format = parts[0];
let datePart = parts[1];


let numbers = datePart.split("-");



let first = Number(numbers[0]);
let second = Number(numbers[1]);
let third = Number(numbers[2]);

let day;
let month;
let year = third;
Comment on lines +2 to +18

Choose a reason for hiding this comment

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

You can use const instead of let for variables that are not reassigned.


if(format === "MDY"){
month = first;
day = second;
}

if (format === "DMY"){
day = first;
month = second;
}
Comment on lines +20 to +28

Choose a reason for hiding this comment

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

If the format is not MDY or DMY, day and month will be undefined. Consider handling this case.
Example where it won’t work parseDateString("MYD 10-21-1983"); -> the result will be:
{ day: undefined, month: undefined, year: 1983 }

You could add an else block to handle that.


let result = {
day: day,month: month, year: year
};


return result;
}

console.log(parseDateString("MDY 10-21-1983"));
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(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
}
Comment on lines +1 to +18

Choose a reason for hiding this comment

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

Good job👍

147 changes: 75 additions & 72 deletions task-4/cleanup.js
Original file line number Diff line number Diff line change
@@ -1,80 +1,83 @@
// Temperature conversion and weather report for City 1
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");
function CelsiusToFahrenheit(c){

Choose a reason for hiding this comment

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

Small typo: CelciusCelsius.

return(c*9/5) + 32;
}
console.log("---");

// Temperature conversion and weather report for City 2
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");
function CelciusToKelvin(c){

Choose a reason for hiding this comment

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

Same here: CelciusCelsius.

return c + 273.15;
}
console.log("---");

// Temperature conversion and weather report for City 3
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");
} else {
console.log("Status: Hot");
function AddDescription(c){
if (c<0){
return "Freezing";
}
if(c<10){
return "cold";
}
if(c<20){
return "Mild";
}
if(c<30){
return "Warm";
}
return "Hot";
}
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");
function getWindChill(celsius, windKmPerHour) {
let windPower = Math.pow(windKmPerHour, 0.16);

let answer = 13.12 +
0.6215 * celsius -
11.37 * windPower +
0.3965 * celsius * windPower;

return answer;
}
function showWeather(cityName, celsius, windSpeed) {

let fahrenheit = CelsiusToFahrenheit(celsius);
let kelvin = CelciusToKelvin(celsius);


let feeling = AddDescription(celsius);
Comment on lines +37 to +41

Choose a reason for hiding this comment

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

You can use const instead of let for variables that are not reassigned.



console.log("Weather Report for " + cityName);
console.log("Temperature: " + celsius + "°C");
console.log("Temperature: " + fahrenheit + "°F");
console.log("Temperature: " + kelvin + "K");
console.log("Status: " + feeling);
console.log("---");


if (windSpeed > 0) {
let chill = getWindChill(celsius, windSpeed);
console.log("Wind chill in " + cityName + ": " + chill + "°C");
}
}

let name1 = "Amsterdam";
let temp1 = 22;
let wind1 = 15;
showWeather(name1, temp1, wind1);


let name2 = "Berlin";
let temp2 = 15;
let wind2 = 20;
showWeather(name2, temp2, wind2);


let name3 = "Copenhagen";
let temp3 = -5;
let wind3 = 25;
Comment on lines +58 to +72

Choose a reason for hiding this comment

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

Nice! we could also further reduce repetition, you could group the city data into an array of objects and iterate over it. This would make adding new cities even easier.

const cities = [
  { name: 'Amsterdam', tempCelsius: 22, windSpeed: 15 },
  { name: 'Berlin', tempCelsius: 15, windSpeed: 20 },
  { name: 'Copenhagen', tempCelsius: -5, windSpeed: 25 },
  { name: 'Dublin', tempCelsius: 8, windSpeed: 10 },
  { name: 'Edinburgh', tempCelsius: 12, windSpeed: 18 },
];

Then call the functions on these in different ways. One of them is through a loop, which is a future topic :)

showWeather(name3, temp3, wind3);

// 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");
let name4 = "Nairobi";
let temp4 = 20;
let wind4 = 12;
showWeather(name4, temp4, wind4);

// 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");
let name5 = "Paris";
let temp5 = -2;
let wind5 = 30;
showWeather(name5, temp5, wind5);