Tell us what’s happening:
Everything seems to be working still 5 of the tests are not passing (18, 19, 21, 22, 24).
Also if I use location instead of locationn in line 10, preview shows a 404 page.
Your code so far
<!-- file: index.html -->
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Weather App</title>
<link href='styles.css' rel='stylesheet'>
</head>
<body>
<button id='get-weather-btn'>Get weather</button>
<select>
<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>
<img id='weather-icon'></img>
<h1 id='main-temperature'></h1>
<h3 id='feels-like'></h3>
<h5 id='humidity'></h5>
<h5 id='wind'></h5>
<h5 id='wind-gust'></h5>
<h5 id='weather-main'></h5>
<h2 id='location'></h2>
<script src='script.js'></script>
</body>
</html>
/* file: script.js */
const select = document.querySelector('select');
const btn = document.getElementById('get-weather-btn');
const icon = document.getElementById('weather-icon');
const temperature = document.getElementById('main-temperature');
const feelsLike = document.getElementById('feels-like');
const humidity = document.getElementById('humidity');
const wind = document.getElementById('wind');
const windGust = document.getElementById('wind-gust');
const weather = document.getElementById('weather-main');
const locationn = document.getElementById('location');
async function getWeather(city) {
try {
let response = await fetch(`https://weather-proxy.freecodecamp.rocks/api/city/${city}`);
let data = await response.json();
return data;
}
catch(err){
console.log(err);
}
}
async function showWeather(city) {
try {
let data = await getWeather(city);
icon.setAttribute('src', data.weather[0].icon ? data.weather[0].icon : 'N/A');
temperature.textContent = data.main.temp ? `Temperature: ${data.main.temp} Celsius` : 'N/A';
feelsLike.textContent = data.main.feels_like ? `Feels like: ${data.main.feels_like}` : 'N/A';
humidity.textContent = data.main.humidity ? `Humidity: ${data.main.humidity}` : 'N/A';
wind.textContent = data.wind.speed ? `Wind speed: ${data.wind.speed} m/s` : 'N/A';
windGust.textContent = data.wind.gust ? `Wind gust: ${data.wind.gust}` : 'N/A';
weather.textContent = data.weather[0].main ? `Weather: ${data.weather[0].main}` : 'N/A';
locationn.textContent = data.name ? `City: ${data.name}` : 'N/A';
return;
}
catch {
alert('Something went wrong, please try again later')
}
}
let selectedOption;
select.addEventListener('change', (e) => {
selectedOption = e.target.value;
});
btn.addEventListener('click', () => {
if(!selectedOption) {
return
}
else {
showWeather(selectedOption)
}
});
/* file: styles.css */
*{
background-color: black;
color: lightgrey;
}
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
