Skip to content

Commit

Permalink
Merge branch 'Alexandra' of https://github.com/Cocofnas/project-weath…
Browse files Browse the repository at this point in the history
…er-app into Alexandra
  • Loading branch information
Your Name alexandrameija@hotmail.com committed Sep 14, 2023
2 parents 5007ab8 + 143d577 commit a599847
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions script.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,17 @@ function fetchWeatherDataByCoordinates(latitude, longitude) {
})
.then((json) => {
const cityName = json.name;
const temperature = json.main.temp;
const temperature = json.main.temp.toFixed(1); //removed all but one decimal
const weatherDescription = json.weather[0].description;
const sunsetTimestamp = json.sys.sunset * 1000;
const sunriseTimestamp = json.sys.sunrise * 1000;
const feelsLike = json.main.feels_like;
const feelsLike = json.main.feels_like.toFixed(1); //removed all but one decimal

// Create Date objects for sunset and sunrise times
const sunset = new Date(sunsetTimestamp);
const sunrise = new Date(sunriseTimestamp);
const sunsetTime = `${sunset.getHours()}:${sunset.getMinutes()}`; //removes seconds
const sunriseTime = `${sunrise.getHours()}:${sunrise.getMinutes()}`; //removes seconds
const currentDayOfWeek = new Date().getDay();

function generateWeatherMessage(description) {
Expand Down Expand Up @@ -55,8 +57,8 @@ function fetchWeatherDataByCoordinates(latitude, longitude) {
<h3>${weekdays[currentDayOfWeek]}</h3>
<p>Temperature: ${temperature}°C</p>
<p>Weather: ${weatherDescription}</p>
<p>Sunrise: ${sunrise.toLocaleTimeString()}</p>
<p>Sunset: ${sunset.toLocaleTimeString()}</p>
<p>Sunrise: ${sunriseTime}</p>
<p>Sunset: ${sunsetTime}</p>
<p>Weather feels like: ${feelsLike}°C</p>
`;
})
Expand Down Expand Up @@ -113,15 +115,15 @@ function fetchWeatherData() {
const morningItem = forecastItems.find((item) => item.dt_txt.includes("09:00"));
const eveningItem = forecastItems.find((item) => item.dt_txt.includes("21:00"));

if (morningItem && eveningItem) {
const morningTemperature = morningItem.main.temp; // Temperature at 9:00 AM
const eveningTemperature = eveningItem.main.temp; // Temperature at 9:00 PM
const morningFeelsLike = morningItem.main.feels_like; // "Feels like" temperature at 9:00 AM
const eveningFeelsLike = eveningItem.main.feels_like; // "Feels like" temperature at 9:00 PM
const morningDescription = morningItem.weather[0].description; // Weather description at 9:00 AM
const eveningDescription = eveningItem.weather[0].description; // Weather description at 9:00 PM
const morningHumidity = morningItem.main.humidity; // Humidity at 9:00 AM
const eveningHumidity = eveningItem.main.humidity; // Humidity at 9:00 PM
if (morningItem && eveningItem) {
const morningTemperature = morningItem.main.temp.toFixed(1); // Temp at 9 am
const eveningTemperature = eveningItem.main.temp.toFixed(1); // Temp at 9 pm
const morningFeelsLike = morningItem.main.feels_like.toFixed(1); // Feels like at 9 am
const eveningFeelsLike = eveningItem.main.feels_like.toFixed(1); //Feels like at 9 pm
const morningDescription = morningItem.weather[0].description; // Weather description at 9 am
const eveningDescription = eveningItem.weather[0].description; // Weather description at 9 pm
const morningHumidity = morningItem.main.humidity; // Humidity at 9am
const eveningHumidity = eveningItem.main.humidity; // Humidity at 9 pm

// Get the day of the week for the date
const weekday = new Date(date).getDay();
Expand Down

0 comments on commit a599847

Please sign in to comment.