I'm trying to create a button whose change background color (to green) when it is cliked. But when it is cliked againg the button returns to the original background color (from orange).
var btn1 = document.getElementById("btn-1")

if (btn1.style.backgroundColor = "orange") {
        btn1.addEventListener("click", function () {
        btn1.style.backgroundColor = "green"
    })
} else {btn1.addEventListener("click", function () {
    btn1.style.backgroundColor = "orange"
})
    }

Could you help me? Thx!
I'm trying to create a button whose change background color (to green) when it is cliked. But when it is cliked againg the button returns to the original background color (from orange).

Change Button's color twice when it's clicked


let button = document.getElementById("button");
    button.style.backgroundColor = "orange";

button.addEventListener("click", function () {
        if(button.style.backgroundColor == "orange"){
           button.style.backgroundColor = "green";
        } else button.style.backgroundColor = "orange";
})
<button id="button">test</button>



how i understand you: you can set starter color of button to orange;
and then add EventListener to button with this logic:
-if the color of the button is orange - change to green
or if the color is not orange - change to orange
