Tell us what’s happening:
My project is failing tests 18-22 and I don’t know why. Everything is working the way it should and updating correctly
Your code so far
<!-- file: index.html -->
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Weather App</title>
<link rel="stylesheet" href="styles.css" />
</head>
<body>
<div id="weather-container">
<img id="weather-icon">
<p id="main-temperature"></p>
<p id="feels-like"></p>
<p id="humidity"></p>
<p id="wind"></p>
<p id="wind-gust"></p>
<p id="weather-main"></p>
<p id="location"></p>
</div>
<div id ="options-container">
<select id="cities" name="cities">
<option value=""></option>
<option value="new york">New York</option>
<option value="los angeles">Los Angeles</option>
<option value="chicago">Chicago</option>
<option value="paris">Paris</option>
<option value="tokyo">Tokyo</option>
<option value="london">London</option>
</select>
<button type="button" id="get-weather-btn">Get Weather!</button>
</div>
<script src="script.js"></script>
</body>
</html>
/* file: styles.css */
* {
box-sizing: border-box;
}
body {
background-color: lightcyan
}
#weather-container {
height: 75vh;
}
#options-container {
height: 10vh;
display: flex;
justify-content: space-around;
align-items: center;
}
#weather-container, #options-container{
width: 90vw;
margin: 5vh auto;
background-color: white;
border: 3px solid #00aaaa;
border-radius: 20px;
}
#cities {
width: 50%;
}
#get-weather-btn {
background-color: #00aaaa;
color: white;
border: none;
font-style: verdanna;
border-radius: 20px;
}
#get-weather-btn:hover {
cursor: pointer;
}
#cities, #get-weather-btn {
height: 80%;
font-size: 1.2rem;
}
/* file: script.js */
const container = document.getElementById("weather-container");
const cities = document.getElementById("cities");
const getWeatherBtn = document.getElementById("get-weather-btn");
const getWeather = async (city) => {
try {
let weather = await fetch(`https://weather-proxy.freecodecamp.rocks/api/city/${city}`).then(response => response.json());
return weather
} catch (error) {
alert("Something went wrong, please try again later")
console.log(error)
}
}
const showWeather = async (city) => {
try {
const data = await getWeather(city)
document.getElementById("location").innerText = data.name;
document.getElementById("weather-icon").src = data.weather[0]?.icon
document.getElementById("weather-main").innerText = data.weather[0].main || "N/A";
document.getElementById("main-temperature").innerText = data.main.temp || "N/A";
document.getElementById("feels-like").innerText = data.main.feels_like || "N/A";
document.getElementById("humidity").innerText = data.main.humidity || "N/A";
document.getElementById("wind").innerText = data.wind.speed || "N/A";
document.getElementById("wind-gust").innerText = data.wind.gust || "N/A";
} catch (err) {
alert("Something went wrong, please try again later")
}
}
getWeatherBtn.addEventListener("click", () => {
if (cities.value === "") {
return;
} else {
showWeather(cities.value);
}
})
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/139.0.0.0 Safari/537.36
Challenge Information:
Build a Weather App - Build a Weather App
https://www.freecodecamp.org/learn/full-stack-developer/lab-weather-app/lab-weather-app