For an assignment in JavaScript and jQuery, I have an object where the keys are either state names or state abbreviations (e.g. Nevada, Washington, PA, NY, etc.) and the values are either true or false (as Booleans not strings).
I'm using an API to get the state in which a webpage's visitor is located, and I'm storing that state into localStorage as well as into a JavaScript variable called state:
$.get('https://api.geoapify.com/v1/ipinfo?&apiKey=de43045d1ab840e9b94f07dee35c6935', function(response){
console.log('State received...');
state = response.state.name;
localStorage.setItem('state', state)
console.log(state)
});
I need to check what the value is (true
or false
) for the visitor's state's name as a key in the object. If the value is true, I need to display a certain set of strings in the assignment's HTML. These strings are in another object called products
which has 2 sub-objects.
I'm not allowed to edit the HTML at all. The HTML makes 3 columns and each column has divs for name, info blurb, and a product image. The 3 columns all have the same-named classes for name, info blurb, and product image divs, but I only should be changing one of the column's values.
This is what I have written so far but it's not changing anything in the CodePen. And I'm stumped here:
state_keys = Object.keys(theObjectContainingStates);
if (theObjectContainingStates.["state"] == true) {
$('.med_card_info-name').html(products[1].name)
$('.med_card_info-blurb').html(products[1].blurb)
$('.med_card_info-image').html(products[1].imgSrc)
}
I think my first issue is am I even doing the right thing to check the key in the States Object that has the same name as the visitor's state?
if (theObjectContainingStates.["state"] == true) {
}