I am facing an issue with setting up an alert on button click. When I click the button, nothing happens. Can you please check? The expected behavior is that upon clicking the button, there should be an alert showing 'foo' if the box is checked and 'bar' if it is not checked. However, currently, no alerts are being displayed on button click.
function myFunction(){
if (document.getElementById('foo').checked) {
alert('foo');
} else {
alert('bar');
}
}
<input type="radio" name="zing" id="foo" />
<input type="radio" name="zing" id="bar"/>
<button onclick="myFunction()">
hello
</button>