samedi 20 juillet 2019

Finding if statement has 0 and returning true and false (if/else)

I am struggling to on the if/else statements when there are multiple numbers. For example when finding true or false if there is a 0 in a string of numbers. There examples where [5, 0 , 2] and [1, 3, 5]. I cannot figure out what to do when there are multiple numbers. Can someone please help me understand this?

    function testNum(a) {

    if (a = [5, 0, 2]);
    return true;
    else if (a = [1, 3, 5]);
    return false;

    }

    console.log(testNum[5, 0, 2]);
    console.log(testNum[1, 3, 5]);

    return a;
    result: Error: Unexpected token else

function testNum(a) {
if (a > [5, 0, 2]) {
return "true";
} else {
return "false";
}
}

console.log(testNum([5, 0, 2]);
console.log(testNum([1, 3, 5]);
return a;
result: Error: Unexpected token else



    function testNum(a) {

    if (a = [5, 0, 2]);
    return true;


    }

    console.log(testNum[5, 0, 2]);
    console.log(testNum[1, 3, 5]);

    return a;
    result: a is not defined

I expect to return a true and a false.

Aucun commentaire:

Enregistrer un commentaire