+ 2
Dose anyone know what I did wrong? Plz help! Warning JavaScript.
https://sololearn.com/compiler-playground/Wf9IloK58bY4/?ref=app
1 Answer
+ 6
There are a couple of errors in your code:-
1.The id value is surrounded by single/double quotes and no semicolon required.
2.Mybutton variable is defined inside the function urmom(), so it can't be used outside that function.To solve this issue, insert the if statement inside the function.
The code will work perfectly but may not be like you expected.
I think, you're trying this one:-
function urmom() {
const Mybutton = document.getElementById("Mybutton");
if (Mybutton.textContent === "click") {
Mybutton.textContent = "clicked";
} else if (Mybutton.textContent === "clicked") {
Mybutton.textContent = "double clicked";
}
}