Fooling around with a script to make a random square move on any web page with arrow keys. I'm encountering an error saying "e" does not exist.
var page = document.getElementsByTagName("body")[0];
var bruhmoment = document.createElement("div");
bruhmoment.style.height = "100px";
bruhmoment.style.width = "100px";
bruhmoment.style.display = "block";
function getColor(){
var color = "#";
for(var i = 0; i < 6; i++){
color += ( Math.round(Math.random()) * 9 );
}
return color;
}
bruhmoment.style.backgroundColor = getColor();
bruhmoment.style.zindex = 1e9;
bruhmoment.id = "bruhmoment";
bruhmoment.style.marginLeft = "0px";
bruhmoment.style.marginBottom = "100px";
bruhmoment.xaxis = 0;
bruhmoment.yaxis = 0;
function move(e){
switch(e.which){
case 39:
xaxis += 10;
bruhmoment.style.marginLeft = xaxis + "px";
break;
case 37:
xaxis -= 10;
bruhmoment.style.marginLeft = xaxis + "px";
break;
case 38:
yaxis += 10;
bruhmoment.style.marginBottom = yaxis + "px";
break;
case 40:
xaxis -= 10;
bruhmoment.style.marginBottom = yaxis + "px";
break;
case 67:
bruhmoment.style.backgroundColor = getColor();
break;
}
}
page.onkeydown = move(event);
page.appendChild(bruhmoment);
Out of all the things in this code that could possibly be an error, I'm not sure how JavaScript chose that specific error to have a quarrel with. Could someone enlighten me?
page.onkeydown = move, andfunction move(evt){}. Note that after that, you have to declaree = eventafter that.