Home > Back-end >  JavaScript : 3 little problem about syntax or something
JavaScript : 3 little problem about syntax or something

Time:01-08

I am new about codind. I am working about a Tic Tac Toe project. But a problem how İ doesn’t expect was spawn.

const verifyVictory = () => {
    if(
        (state.c1 = state.c2 && state.c2 == state.c3 && state.c1 > 0) ||
        (state.c4 = state.c5 && state.c5 == state.c6 && state.c4 > 0) ||
        (state.c7 = state.c8 && state.c8 == state.c9 && state.c7 > 0) ||

        (state.c1 = state.c4 && state.c4 == state.c7 && state.c1 > 0) ||
        (state.c2 = state.c5 && state.c5 == state.c8 && state.c2 > 0) ||
        (state.c3 = state.c6 && state.c6 == state.c9 && state.c3 > 0) ||

        (state.c1 = state.c5 && state.c5 == state.c9 && state.c1 > 0) ||
        (state.c3 = state.c5 && state.c5 == state.c7 && state.c3 > 0) 
    ){
        return true;
    } else if {
        state.c1 != 0 &&
        state.c2 != 0 &&
        state.c3 != 0 &&
        state.c4 != 0 &&
        state.c5 != 0 &&
        state.c6 != 0 &&
        state.c7 != 0 &&
        state.c8 != 0 &&
        state.c9 != 0
    } {
        return null;
    } else {
        return false;
    }
};

I don’t know how can I fix it. I don’t know how to search to find solution on my issue in google.

My VS code editor with problems underligned

Thank

I tried to search on google but nothing about what I can understand..

CodePudding user response:

It looks like there is a syntax error in the code you provided. The issue is with the else if statement: it is missing the condition that it is testing. Here is the corrected code:

 ){
    return true;
} else if (   <---------- here is the problem
    state.c1 != 0 &&
    state.c2 != 0 &&
    state.c3 != 0 &&
    state.c4 != 0 &&
    state.c5 != 0 &&
    state.c6 != 0 &&
    state.c7 != 0 &&
    state.c8 != 0 &&
    state.c9 != 0
) {
    return null;
} else {
    return false;
 }
};

CodePudding user response:

you have opened else if with conditions inside wrong brackets.

else if (
    state.c1 != 0 &&
    state.c2 != 0 &&
    state.c3 != 0 &&
    state.c4 != 0 &&
    state.c5 != 0 &&
    state.c6 != 0 &&
    state.c7 != 0 &&
    state.c8 != 0 &&
    state.c9 != 0
) {
    return null;
}
  • Related