Skip to content

Commit

Permalink
Fix bugs in error handling, if specific weather data not available.
Browse files Browse the repository at this point in the history
  • Loading branch information
seankelliher committed Apr 16, 2024
1 parent 9b5d412 commit f6b86a2
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions app/elements.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ function completeElements (
const tempConvertToF = (Math.round(temperature * 1.8) + 32);

// TEMP - append content.
if (temperature === "") {
if (temperature === null || temperature === "") {
tempC.textContent = "Temperature is unavailable.";
tempF.textContent = "Temperature is unavailable.";
} else {
Expand All @@ -85,7 +85,7 @@ function completeElements (
const cond = document.createElement("dd");

// CONDITION - append content.
if (condition === "") {
if (condition === null || condition === "") {
cond.textContent = "Current conditions are unavailable.";
} else {
cond.textContent = `Current conditions are ${condition}.`;
Expand All @@ -104,10 +104,10 @@ function completeElements (
// WINDSPEED - tidy windSpeed.
let wsKm;
let wsMi;
if (windSpeed < 1 || windSpeed === null) {
if (windSpeed < 1) {
wsKm = "Winds are calm";
wsMi = "Winds are calm";
} else if (windSpeed === "") {
} else if (windSpeed === null || windSpeed === "") {
wsKm = "Winds are unavailable.";
wsMi = "Winds are unavailable.";
} else {
Expand All @@ -127,10 +127,8 @@ function completeElements (
wd = " from the Southwest.";
} else if (windDirectection > 270 && windDirectection <= 360) {
wd = " from the Northwest.";
} else if (windDirectection === null) {
wd = "with no direction.";
} else {
wd = "wind direction unavailable.";
wd = " (wind direction unavailable)";
}

// WIND - append content, elements.
Expand All @@ -155,7 +153,7 @@ function completeElements (
const dewConvertToF = (Math.round(dewpoint * 1.8) + 32);

// DEWPOINT - append content.
if (dewpoint === "") {
if (dewpoint === null || dewpoint === "") {
dewC.textContent = "Dewpoint is unavailable.";
dewF.textContent = "Dewpoint is unavailable.";
} else{
Expand All @@ -170,8 +168,8 @@ function completeElements (

// HUMIDITY - append content, elements.
const rh = Math.round(relativeHumidity);
if (relativeHumidity === "") {
humid.textContent = "Humidity is unavailable.";
if (relativeHumidity === null || relativeHumidity === "") {
humid.textContent = " Humidity is unavailable.";
} else {
humid.textContent = ` Humidity is ${rh}%.`;
}
Expand Down

0 comments on commit f6b86a2

Please sign in to comment.