Local storage help on weather app

Local storage help on weather app
0

#1

I have my code here and want to add a trashcan icon next to every fav city that comes up in the dropdown menu in case you want to remove it. How?


#2

Have you found the trash can icon you want to use?


#3

<i class="fas fa-trash-alt"></i>

This one. I also want to click on the favorite city and have it display. Feeling super pressured right now because it’s due tomorrow and I still need to write tests in chai and mocha.

When I reload the page, it also takes it out of the dropdown menu, but the cities are still in local storage.


#4

Just a slight modification to your for loop which updates option’s innerHTML:

    for (let i = 0; i < favorites.cities.length; i++) {     
      option.innerHTML = `<i class="fas fa-trash-alt"></i> ${favorites.cities[i]}`
    }

You could add event listeners to each trashcan icon and then the use a callback function which removes the element and then updates local storage’s favoriteCities property.

Since you are not creating the dropdown menu from local storage, you will have to write code to do that.


#5

The above code you posted does not give me the icons?


#6

Does your project have the correct library loaded to access the icon?

Edit: I have updated my post to reflect the icon you said you wanted to use. The icon I first referenced was one I used, but I added the following library to the project to use it.

https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css


#7

I’m so pissed at this point I can’t even think straight. Any time I add a city to the local storage dropdown menu and refresh the page, they disappear even though they are in the local storage. How in the hell do I fix this and how do I set it to where if you click “Add city”, it won’t add a string or city that is already in there?


#8

Where in your current code are you generating the dropdown menu from local storage when the page loads?

You will have to write code to make this check and not add it if the city already exists in the applicable local storage property.


#9

I’m very very frustrated right now, I’ve kind’ve given up.


#10

Please someone help me. I’m so frustrated my face is numb.