You should only use function draw()
one time. Try replacing both functions with this code:
function draw() {
background("white");
if (keyDown("left")) {
ghost.setAnimation("ghost_walking");
ghost.mirrorX(+1);
ghost.x = ghost.x - 1;
} else if (keyDown("right")) {
ghost.setAnimation("ghost_walking");
ghost.mirrorX(-1);
ghost.x = ghost.x + 1;
} else {
ghost.setAnimation("ghost");
}
drawSprites();
}