vendredi 26 février 2016

Working code, how can I condense this?

Finished codeacademy and I'm looking to practice and get better at Javascript. Is this coded correctly or should I have made a function for it somehow? Also is there a better place to ask this sort of thing? I have this hosted at http://ift.tt/1WOQJ9E

function anim(e){
    if((e.keyCode === 37)||(e === 37)){
    y = shipLeft;
    shipLeft -= 11;
    y -= 11;
    y.toString();
    y = y + 'px';
    ship.style.left = y;
    changeColor();
    return shipLeft
}
    else if ((e.keyCode === 39) || (e === 39)){
    y = shipLeft;
    shipLeft += 11;
    y += 11;
    y.toString();
    y = y + 'px';
    ship.style.left = y;
    changeColor();
    return shipLeft
    }

Aucun commentaire:

Enregistrer un commentaire