It keeps saying my variable is null even though it is assigned to a button in HTML. It doesn't allow the button press to work. The variable is "clickMe"
var yourName; //global variable accessible to all functions
function showAnotherMessage() {
alert("Hi " + yourName + ".\nThis is an alert message is no longer defined\nin the HTML but in a JavaScript file");
}
function init() {
yourName = prompt("Hi. Enter your name.\nWhen the browser window is first loaded\nthe function containing this prompt window is called.", "Your name");
var clickMe = document.getElementById("buttonclick");
clickMe.onclick = showAnotherMessage;
}
window.onload = init();
var clickMe = document.getElementById("buttonclick");... do you have a html element withid="buttonclick"- exactly "buttonclick", not"buttonClick"or"buttonclick "window.onload = init();should bewindow.onload = init;