Better card validity check in JS card game
This is my new attempt

Game.prototype.isCardLegal = function(card,player){

    var requirements = this.getRequirements();

    if(this.cardsToDraw() &gt; 0 &amp;&amp; card.value !== '7'){
        player.setTask('forced draw');
        return false;
    }

    if (card.color !== requirements.color &amp;&amp; card.value !== requirements.value &amp;&amp; card.value !== 'J') {
        player.setTask('invalid card');
        return false;
    }

    return true;

};


When a card is played the game state will be updated with the required color / value. When the played card is a jack or a 7, the respective requirements are set accordingly. So I don't have to distinguish between the color of the last card palyed and a possible forced color any more, as in both cases the game state property will be updated.

I'm still looking for ideas, though.