samedi 19 septembre 2015

Javascript if/else statements, defining and returning variables?

I'm trying to work on a rock/paper/scissors type game and there's a block of code that doesn't seem to work. There don't seem to be any syntax errors, at least to my eye or knowledge, but the console keeps coming up blank. This is what I came up with - to make it easier I started off by comparing numbers instead of 'rock', 'paper', or 'scissors', and here I just left the a and b variables blank but obviously when testing the code I plugged some numbers in.

function getWinner(a, b) {
    a = ; 
    b = ; 
    var winner;
    if (a === b) {
        winner = 'tie';
    } else if (a > b) {
        winner = 'adam';
    } else if (b > a) {
        winner = 'bob';
    }
    return winner;
}

Please tell me if you see anything wrong or things that could be written better! I'm trying to keep the return statement separate from the if statements.

Aucun commentaire:

Enregistrer un commentaire