Problem with code Javascript

let Button = document.getElementById('Btn');

Button.addEventListener('click', function clicked() {
    if (Button === "click") {
        Button.innerHTML = "clicked";
    } else {
        Button.innerHTML = "not yet";
    }
})

Code runs but it does not do what I want it to do exactly I want, I want the button text to change when I click on the button it must chage click to clicked . Thank you for your time.

I think you can remove “clicked” after the word “function” in your addEventListener.

// html
<button id="Btn">not yet</button>

//javascript
let Button = document.getElementById(‘Btn’);

Button.addEventListener(‘click’, function(){
    Button.innerHTML = "clicked";
})
1 Like
Button === "click"

You’re checking if the Button element is literally the same as the string “click” – it never is because the element is an object. What are you trying to compare it to?

like click it with mouse

You’re checking if the Button element is literally the same as the string "click"

The event only fires if the button is clicked. You can’t check if it’s been clicked, that makes no sense because the stuff inside that function only runs if the button has been clicked.