Wanderlust - Help with Step 24

Hello,

Hope everyone who sees this is doing well.

I’m working on the Requests lesson portion of the Javascript introduction course and I’m stuck on a part of the Wanderlust project. Below my writing, I inserted the code I have for the getForecast async function. When logging jsonResponse to the console, I get an error message saying that forecastUrl, which is part of the const urlToFetch variable, is not defined.

That makes sense to me seeing that I didn’t actually define it anywhere, but neither the video or the directions say anything about defining it before. Did I miss a step or is something else wrong?

Thank you!

My code for the getForecast function:

const getForecast = async() => {
  const urlToFetch = `${forecastUrl}${apiKey}&q=${input.val()}&days=4&hour=11`;
  try {
    const response = await fetch(urlToFetch);
    if (response.ok) {
      const jsonResponse = response.json();
      console.log(jsonResponse);
    }
    else {
      throw new Error('Request failed!');
    }
  } catch (error) {
    console.log(error.message);
  };
}

Blockquote

1 Like

You’re correct in that nothing asked you to define a variable forecastUrl, because the variable you’re looking for is weatherUrl and you defined that in Step 5:

image

1 Like

Hi,

I also need help with this project please, on step 34. The weather api window does not show for me. I cannot figure out the instructions and what exactly I am meant to do. This project seems to have no video and this one step is preventing me from finishing the project.

Here is the instruction:
'Construct a string with the HTML text. Replace the uppercase text (like DAY_TEMP_F ) with the values from the day object. Save this string to the weatherContent variable, and make sure that it is still passed into $weatherDiv.append() .

The current day for the DAY placeholder may present a challenge. You can construct a new JavaScript Date object using the dt property of the day object and use the .getDay() method to get an integer representing the current day of the week. Use the provided weekDays array to retrieve a string with the day’s name.

For the DAY_TEMP_F you’ll need to convert the temperature provided from OpenWeather to Fahrenheit using the following equation: ((DAY_TEMP - 273.15) * 9 / 5 + 32).toFixed(0) . You can get DAY_TEMP from day.main.temp .’

Here is the code I am meant to be adding to:

const renderForecast = (day) => {
// Add your code here:

const weatherContent = createWeatherHTML(day);
$weatherDiv.append(weatherContent);
};

const executeSearch = () => {
$venueDivs.forEach(venue => venue.empty());
$weatherDiv.empty();
$destination.empty();
$container.css(“visibility”, “visible”);
getVenues().then(function(venues){return renderVenues(venues); } )
getForecast().then(function(forecast){return renderForecast(forecast); } )
return false;
}

$submit.click(executeSearch);

Thanks for any help. P.S - I tried using the code from the live project page that was in the browser console but it didn’t work…

I found the solution. It was a small syntax error that I didn’t notice - I placed a return of jsonResponse outside the if statement instead of within…