DEV Community

Discussion on: initLogs 4: Why am I getting [object Promise] when calling an asynchronous function in JavaScript?

Collapse
 
miketalbot profile image
Mike Talbot ⭐

You could just make the click handler async in this case.

submitButton.addEventListener('click', async () => {

            infoBox.style.display = 'grid';
            infoBox.innerText = await callOpenWeather(`http://api.openweathermap.org/data/2.5/weather?q=${inputValue.value}&APPID=${apiKey}`); // Use an api key of openweather api instead of ${apiKey} to make this code work.
            infoBox.style.boxShadow = '0 0 2px 0 #d3d3d3';    

    });
Enter fullscreen mode Exit fullscreen mode
Collapse
 
unsungnovelty profile image
Nikhil • Edited

TIL! That makes the code a little more clean. Let me make the change right away. Thanks @miketalbot !