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.