For some reason, I cannot get my function to perform on the click of a button. I've learned mainly on codeacademy.com and unfortunately they don't give much real world application.
Here is my code:
<script>
var ayee = function() {
confirm("Ready to play?");
var age = prompt("How old are you?");
if (age >= 18) {
document.write("Let's get started then!");
}else{
document.write("You're under 18? Be careful out there....");
}
}
</script>
<button type="button" onclick="ayee" value="click" />
Much thanks.
document.writeafter the page has already loaded... useinnerHTMLor standard DOM functions instead. Also, instead of using anonclickattribute, it's better to attach aclickevent handler to your button by giving it anidand usingdocument.getElementById.