Build a Weather App - Build a Weather App

Tell us what’s happening:

I am failing tests 19 to 23.
Here is my output for London:

I don’t know what I am doing wrong.
Please advise.

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>
    <main>
      <div id="display">
        <img id="weather-icon"></img>
        <p>Main temp: <scan id="main-temperature"></scan></p>
        <p>Feels like: <scan id="feels-like"></scan></p>
        <p>Humidity: <scan id="humidity"></scan></p>
        <p>Wind speed: <scan id="wind"></scan></p>
        <p>Wind gust speed: <scan id="wind-gust"></scan></p>
        <p>Main weather type: <scan id="weather-main"></scan></p>
        <p>Location: <scan id="location"></scan></p>
      </div>
      <br>
      <div id="input">
        <select id="city">
          <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 id="get-weather-btn">Get Weather</button>
      </div>
    </main>
    <script src="./script.js"></script>
  </body>
</html>
/* file: styles.css */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  background-color: lightBlue;
}

div {
  margin: 2px;
  border-radius: 5px;
  border: 2px solid blue;
}

#display {
  height: 200px;
}

#input {
  width: 310px;
}

select {
  margin: 8px 8px 8px 15px;
  padding: 5px 2px;
}

button {
  cursor: pointer;
  margin: 8px 8px 8px 15px;
  padding: 8px;
  font-size: 16px;
  width: 150px;
  /* height: 30px; */
}

img {
  color: black;
  border-color: red;
  width: 30px;
  height: 30px;
}

/* file: script.js */
const btn = document.getElementById("get-weather-btn");
const city = document.getElementById("city");
const img = document.getElementById("weather-icon");
const mainTemp = 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 weatherMain = document.getElementById("weather-main");
const loc = document.getElementById("location");

const displayWeather = () => {
  const selectedCity = city.value;
  if (selectedCity === "paris") {
    alert("Something went wrong, please try again later");
  } else {
    showWeather(selectedCity);
  }
}

let getWeather = async (city) => {
  try {
    const res = await fetch('https://weather-proxy.freecodecamp.rocks/api/city/' + city);
    return await res.json();
  }
  catch (error) {
    alert("Something went wrong, please try again later");
    console.log(error);
  };
}

const NA = (str, measure) => str ? str + measure : "N/A";

let showWeather = async (city) => {
  clearWeather();
  const weatherData = await getWeather(city);
  if (weatherData.error) {
    alert("Something went wrong, please try again later");
  } else {
    img.src = weatherData.weather[0].icon;
    mainTemp.textContent = NA(weatherData.main.temp, "°C");
    feelsLike.textContent = NA(weatherData.main.feels_like, "°C");
    humidity.textContent = NA(weatherData.main.humidity, "%");
    wind.textContent = NA(weatherData.wind.speed, "m/s");
    windGust.textContent = NA(weatherData.wind.gust, "m/s");
    weatherMain.textContent = NA(weatherData.weather[0].main, "");
    loc.textContent = weatherData.coord ?
      `Latitude: ${weatherData.coord.lat}, Longitude: ${weatherData.coord.lon}` :
      "N/A";
  }
}

const clearWeather = () => {
  img.src = "";
  mainTemp.textContent = "";
  feelsLike.textContent = "";
  humidity.textContent = "";
  wind.textContent = "";
  windGust.textContent = "";
  weatherMain.textContent = "";
  loc.textContent = "";
}

btn.addEventListener("click", displayWeather);

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:157.0) Gecko/20100101 Firefox/157.0

Challenge Information:

Build a Weather App - Build a Weather App

GitHub Link: freeCodeCamp/curriculum/challenges/english/blocks/lab-weather-app/66f12a88741aeb16b9246c59.md at main · freeCodeCamp/freeCodeCamp · GitHub

Hi @ambradnum,

The location should be the name of the city, not the latitude and longitude, but I give you points for precision! :nerd_face:

Happy coding