How can the issue of the checkbox always returning false in the JavaScript function be resolved?

The issue of the checkbox always returning false in the JavaScript function can be resolved by ensuring that the checkbox element is correctly selected using its ID or class. Additionally, make sure that the JavaScript function is properly handling the checkbox state and returning the correct value.

<input type="checkbox" id="myCheckbox">
<button onclick="checkCheckbox()">Check Checkbox</button>

<script>
function checkCheckbox() {
    var checkbox = document.getElementById("myCheckbox");
    
    if (checkbox.checked) {
        alert("Checkbox is checked");
    } else {
        alert("Checkbox is not checked");
    }
}
</script>