Tell us what’s happening:
I’m having issues with test 23 & 24 which has to do with error
Your code so far
<!-- file: index.html -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Weather App</title>
<link rel="stylesheet" href="styles.css" />
</head>
<body>
<div id="weather-display">
<img id="weather-icon" alt="Weather Icon">
<div id="main-temperature" class="weather-info"></div>
<div id="feels-like" class="weather-info"></div>
<div id="humidity" class="weather-info"></div>
<div id="wind" class="weather-info"></div>
<div id="wind-gust" class="weather-info"></div>
<div id="weather-main" class="weather-info"></div>
<div id="location" class="weather-info"></div>
</div>
<div id="weather-form">
<label for="city-select">Weather for:</label>
<select id="city-select">
<option value="">Select a city</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 id="get-weather-btn">Get Weather</button>
</div>
<script src="script.js"></script>
</body>
</html>
/* file: styles.css */
body {
font-family: Arial, sans-serif;
background-color: #e0f7fa; /* light blue-green */
margin: 0;
padding: 20px;
}
/* Weather display card */
#weather-display {
background-color: #ffffff; /* white card */
border-radius: 15px;
box-shadow: 0 4px 8px rgba(0,0,0,0.2);
padding: 30px;
margin-bottom: 20px;
text-align: center;
}
#weather-icon {
width: 100px;
height: 100px;
}
#main-temperature {
font-size: 2rem;
font-weight: bold;
margin-top: 10px;
}
/* Form container */
#weather-form {
background-color: #80cbc4; /* teal-ish */
border-radius: 10px;
padding: 20px;
display: flex;
align-items: center;
justify-content: center;
gap: 10px;
}
#weather-form label {
font-weight: bold;
}
select, button {
padding: 10px;
border-radius: 5px;
border: 1px solid #555;
font-size: 1rem;
}
button {
background-color: #4db6ac; /* darker teal */
color: white;
cursor: pointer;
transition: background-color 0.2s ease;
}
button:hover {
background-color: #00897b; /* hover color */
}
/* Weather info text */
.weather-info {
margin: 5px 0;
font-size: 1rem;
}
/* file: script.js */
async function getWeather(city) {
try {
const response = await fetch(`https://weather-proxy.freecodecamp.rocks/api/city/${city}`);
const data = await response.json();
return data;
} catch (error) {
console.log(error);
throw error;
}
}
async function showWeather(city) {
if (!city) return;
try {
const data = await getWeather(city);
document.getElementById('weather-icon').src = data?.weather?.[0]?.icon ?? '';
document.getElementById('main-temperature').textContent = data?.main?.temp ?? 'N/A';
document.getElementById('feels-like').textContent = data?.main?.feels_like ?? 'N/A';
document.getElementById('humidity').textContent = data?.main?.humidity ?? 'N/A';
document.getElementById('wind').textContent = data?.wind?.speed ?? 'N/A';
document.getElementById('wind-gust').textContent = data?.wind?.gust ?? 'N/A';
document.getElementById('weather-main').textContent = data?.weather?.[0]?.main ?? 'N/A';
document.getElementById('location').textContent = data?.name ?? 'N/A';
} catch (error) {
alert('Something went wrong, please try again later.');
}
}
document.getElementById('get-weather-btn').addEventListener('click', () => {
const city = document.getElementById('city-select').value;
showWeather(city);
});
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Safari/537.36
Challenge Information:
Build a Weather App - Build a Weather App