Weather App - Technical questions

Weather App - Technical questions
0.0 0

#1

Hello,

I’m working on the weather app project, and trying to organize my code and make it cleaner.

I’m using the weather description to determine which background image to display. If description includes certain keywords, the background image is chosen.

I’m trying to capitalize the first letter in each word in the description. I try to wrap it in a function (line 42), and return the new description after it has been manipulated (split, replaced, joined). However, when I pass the function into the function that determines the background-image (line 75), I get an error.

The other question is with toggling between Celsius and Fahrenheit (line 61). I have a variable called unit that changes depending on the current unit of the temperature. If I put the variable inside the function, it will only change once to Fahrenheit, but if the variable is placed outside the function scope, it can toggle back and forth. Why does it work outside, but not inside the function?

Thanks in advance!


#2

You can’t apply desc = desc.toLowerCase(); on a function.

Here is the problem (spoiler)

displayWeather([city, temperature, description()]);

This is how you call a function.


#3

Ah thank you. It didn’t cross my mind that I had to call it too.

Would you have any insight on the “unit” variable on line 60? Why the variable can change when it’s outside the function, but not when it’s inside?

Thanks again!


#4

If it is inside then it is a local var which you are initializing to “celsius” every time.


#5

Thanks so much for the help!