mercredi 29 juillet 2020

Javascript if else repetition

I'm new to Javascript so please don't judge me... I have a code and I want to avoid repetition of the code, is there a way to do it otherwise?

if (dir_x > 0) {
    x++;
    if (dir_y > 0) {
        y++;
    } else {
        y--;
    }
} else {
    x--;
    if (dir_y > 0) {
        y++;
    } else {
        y--;
    }
}

Aucun commentaire:

Enregistrer un commentaire