Weather API questions

Weather API questions
0

#1

Hey guys, anyone have a way of being able to turn these dates into the corresponding day? I want “Mon, Tue, Wed, etc.” but just having issues understanding how to do it. Perhaps an object of all the days? Maybe a switch statement, just unsure of where to go from here. Also, does anyone have an idea about removing the search bar white background and outline? I just want to write the city on a hr


#2

There is a method named getDay which you can call on a Date object to get a number 0 through 6 with 0 being Sunday and 6 being Saturday. One approach is to use an object with properties 0 through 6 and the corresponding day of week string:

var daysOfWeek = {0: 'Sun', 1: 'Mon', etc...}

or just use an array containing the day strings:

['Sun', 'Mon', etc...]

The you could just reference the applicable day string with bracket notation and the value you get back from using the getDay method. The following assumes that myDate already contains the correct Date object on which you will use the getDay method.

const dayIndex = myDate.getDay();
daysOWeek[dayIndex];

I will let you do your own research to figure out how to convert a string date like “2018-09-17” into a JavaScript Date object.


#3

You’re amazing once again. Thank you so much.


#4

How would I go about getting any city I search for in the search box? I see q= …but unsure of how to implement it. Do I add it to the original api call or do I have to make another call on the “GO” event listener?


#5

You can try algolia places. If you check the docs you’ll see it’s pretty easy to set up an autocompleting input that only takes cities.