I’m learning javascript and I’m testing out the if condition. I want to display an alert box only if a button has been clicked. But the alert message pops up without the condition being met(the button being clicked).
Javascript code:
//adding an event listener to the button element:
var hasClicked= false
$("#click").on("click", function () {
hasClicked= true
alert("working");
})
if (hasClicked=true) {
alert("condition met")
}