function change_text(a){
if (a == Canberra){
var x = document.getElementById("a");
document.x.innerHTML = "Correct!";
}
else{
var x = document.getElementById("a");
document.x.innerHTML = "Incorrect!";
}
}
<figure>
<button onclick="change_text(Melbourne)"> Melbourne! </button>
<figcaption id="Melbourne"> </figcaption>
</figure>
<figure>
<button onclick="change_text(Canberra)"> Canberra! </button>
<figcaption id = "Canberra"> </figcaption>
</figure>
Hello, i am new to JS/HTML. I intended to create some buttons with a captions. But the captions should only appear when a corresponding button is clicked. So far it was the easiest to take the figure tag, to have the caption right below the button. The function should take as parameters, the city name and depending on which button pressed the caption should show/change to correct/incorrect.
I am really new to this and i do not understand if anything here what i did makes sense, so i am thankful for any help.