Javascript function event

Hi, i have got another pen on codepen i am trying to make a button and ask two questions and change the H1 to the emoji and a new h1 after pressing the button to the ones in the javascript. This is the codepen:

This is the JS Code:

 function changeCity() {
        let city = prompt("What city do you live in?");
        let temperature = prompt("What temperature is it?");
        let heading = document.querySelector("h1")
        
        if (temperature >= 0) {
            heading.innerHTML"😃 Currently " + temperature + "in "+ city + "!";
        } else {
            heading.innerHTML"😰  Currently " + temperature + "in "+ city + "!";
        }
    }
    let changeCityButton = document.querySelector("button");
    changeCity.addEventListener("click",changeCity);

You are missing the assignment operator = to assign this value to the heading’s innerHTML. ( in both if and else ).

That was a good move from you that you changed the variable name from changeCity to changeCityButton cause you already have a function named changeCity as this outputs an error of redeclaration error. But you missed to change it again in the addEventListener below to be changeCityButton as well.

hmh, i changed it to changeCityButton for the click and i assigned = (equal), but it is still not working. What the heck am i doing wrong here?

It is not working because you are not attaching the click event to the button

    let changeCityButton = document.querySelector("button");
    changeCity.addEventListener("click",changeCityButton);

the logic should be, when a user clicks on the button then the changeCity function should fire and ask those questions.

But right now you are trying to do a click event for the changeCity function.
basically you have it reversed.
Click events are for buttons.

once you fix the logic, then it will work

I figured it out myself, but thanks. I had to think about it and follow the logic… :grinning:. When you click it you see the update.