I'm trying to get this red square moving but I can't get it to work. (I checked the code in a code error finder and it said that there were no errors).
here's the code
var player = null;
function restart(player) {
player = document.getElementById("player");
player.style.top = '0px';
player.style.left = '0px';
}
var x = [0,'px'];
var y = [0,'px'];
function moveDown() {
x[0] + 100;
player.style.top = x[0] + x[1];
}
function moveUp() {
x[0] - 100;
player.style.top = x[0] + x[1];
}
function moveRight() {
y[0] + 100;
player.style.left = y[0] + y[1];
}
function moveleft() {
y[0] - 100;
player.style.left = y[0] + y[1];
}
function move(p) {
var key = p.which || p.keyCode;
switch (key) {
case (87😞
moveUp();
break;
case (83😞
moveDown();
break;
case (68😞
moveRight();
break;
case (65😞
moveLeft();
break;
}
}
window.onLoad = restart;
The id "player" is the red square.
the key codes in order stand for:
w
a
s
d
Can anyone help.