Skip to content Skip to sidebar Skip to footer

Check Variables In Javascript Fails

I've made a card drawing programm to draw three cards. Now I like to avoid that one card is added multiple times. So, I made a little function to check: function check() {

Solution 1:

Everything is OK with this piece of code. Simple check:

var card1 = 'one',
    card2 = 'two',
    card3 = 'three';

function check()
{
    if (card2 == card1 || card3 == card2 || card3 == card1 )
    {
        alert("double card")
    }
    else {
        alert("they are different");
    }
}

check();

Leve demo -- http://jsfiddle.net/sy4tetwn/

The problem is somewhere else in your code.


Solution 2:

Thanks all for your contribution. I finally found a solution. I was triggered by the remark of itdoesntwork to state the results of the console.log IN the function.

function check()
    {
        var result1=" "
        var result2=" "
        var result3=" "
        result1= JSON.parse(sessionStorage.positie1)
        result2= JSON.parse(sessionStorage.positie2)
        if (ak == 3) {
        result3= JSON.parse(sessionStorage.positie3)
        }
        //console.log(result1, result2, result3);
        if (result2 == result1 || result3 == result2 || result3 == result1 )
        {
        alert("double card")
        ak=ak-1;
        }
     }

Post a Comment for "Check Variables In Javascript Fails"