Tell us what’s happening:
Hi! My codes doesn’t pass the test 18,19,20,21 and 22. I have tried several time but no result. I need a help. Thank you
Weather App
</span>
<span>
<img src=""
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 class="main-container">
<div class="holder-container">
<p id="location"></p>
<p>
<span id="main-temperature">
</span>
<span>
<img src="" alt="weater item" id="weather-icon">
</span>
<span id="main">
</span>
</p>
<p>Feels like:
<span id="feels-like">
</span>
</p>
<p>Wind:
<span id="wind">
</span>
</p>
<p>Humidity:
<span id="humidity">
</span>
</p>
<p>Gust:
<span id="wind-gust">
</span>
</p>
<p>
<span id="weather-main">
</span>
</p>
</div>
<div class="wether-icons">
<h1>
WHEATHER FOR:
</h1>
<select>
<option value=""></option>
<option value="london">London</option>
<option value="tokyo">Tokyo</option>
<option value="los angeles">Los Angeles</option>
<option value="chicago">Chicago</option>
<option value="new york">New York</option>
<option value="paris">Paris</option>
</select>
<button id="get-weather-btn">
Get Weather
</button>
</div>
</div>
</div>
<script src="script.js"></script>
</body>
</html>
/* file: script.js */
const weatherButton=document.querySelector("#get-weather-btn");
const selectCity=document.querySelector("select");
const weatherImg=document.querySelector("#weather-icon");
const mainTemp=document.querySelector("#main-temperature");
const feelsLike=document.querySelector("#feels-like");
const humidityEl=document.querySelector("#humidity");
const windElement=document.querySelector("#wind");
const windGust=document.querySelector("#wind-gust");
const weatherMain=document.querySelector("#weather-main");
const cityName=document.querySelector("#location");
const mainCondition=document.querySelector("#main");
async function getWeather(city) {
try {
const response = await fetch(`https://weather-proxy.freecodecamp.rocks/api/city/${city}`);
if (!response.ok) {
throw new Error("Weather data is unavailble");
}
const data = await response.json();
return data;
} catch (error) {
console.log(error);
return;
}
}
async function showWeather(city) {
if(!city){
return;
}
const weatherData=await getWeather(city);
if(!weatherData||weatherData.error){
alert("Something went wrong, please try again later");
return;
}
else{
const {weather,main,wind,name} = weatherData;
cityName.textContent=name||'N/A';
mainTemp.textContent=main.temp? main.temp+'°C':'N/A';
mainCondition.textContent= weather[0].main? weather[0].main :"N/A";
weatherImg.src=weather[0].icon? weather[0].icon:'';
humidityEl.textContent=main.humidity? main.humidity+"%":'N/A';
feelsLike.textContent=main.feels_like? main.feels_like +"°C": 'N/A';
windElement.textContent=wind.speed? wind.speed+"m/s":'N/A';
windGust.textContent=wind.gust? wind.gust+"m/s":'N/A';
}
return weatherData;
}
weatherButton.addEventListener("click", ()=>{
showWeather(selectCity.value);
});
/* file: styles.css */
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body{
background-color: #45D9BE;
font-family: Cambria, Cochin, Georgia, Times, 'Times New Roman', serif
}
.main-container{
background-color: inherit;
width: 80%;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
margin: 20px auto;
}
.holder-container{
background-color: #E5E7EB;
width: 100%;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
border: 2px solid #3F3F46;
border-radius: 30px;
padding: 30px;
font-size: 1.2rem;
}
.wether-icons{
width: 100%;
margin-top: 50px;
display: flex;
justify-content: space-between;
border: 2px solid #3F3F46;
border-radius: 30px;
padding: 30px;
font-size: 1.3rem;
}
#get-weather-btn{
width: 200px;
font-size: 1.2rem;
text-align: center;
border: 2px solid #A50C36;
font-weight: 200;
border-radius: 20px;
}
select{
width: 200px;
font-size: 1.2rem;
padding: 10px;
border-radius: 10px;
border: 2px solid #A50C36;
}
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/148.0.0.0 Safari/537.36
Challenge Information:
Build a Weather App - Build a Weather App


