0

hi everyone ,,

i have this code below. It seems correct but there is an error. it says here that unexpected token else.

function w_tax1() {

        var z = [0.0,1,0,833,2500,5833,11667,20833,41667];
        var sme = [50,1,4167,5000,6667,10000,15833,25000,45833];
        var me1s1 = [75,1,6250,7083,8750,12083,17917,27083,47917];
        var me2s2 = [100,1,8333,9167,10833,14167,20000,29167,50000];
        var me3s3 = [125,1,10417,11250,12917,16250,22083,31250,52083];
        var me4s4 = [150,1,12500,13333,15000,18333,24167,33333,54167];

        var exception = [0,0,41.67,208.33,708.33,1875,4166.67,10416.67];
        var status = [0,0.05,0.1,0.15,0.2,0.25,0.30,0.32];

        var t_sal = document.getElementById("t_sal").value;
        var x,y,z,a,b,c;
        var dependent25 = document.getElementById("selection25").value;

        if(dependent25 === "z") {
            for(x =0;x<z.length;x++) {
            if (t_sal > z[x] && t_sal < z[x + 1]) {
                var nearest_number = z[x];
                var total = ((t_sal - nearest_number) * status[x-1]) + exception[x-1];
                console.log(total);

            }   
        }
        else if(dependent25 === "sme") {
            for(y=0;y<sme.length;y++) {
            if (t_sal > sme[y] && t_sal < sme[y + 1]) {
                var nearest_number1 = sme[y];
                var total1 = ((t_sal - nearest_number1) * status[y-1]) + exception[y-1];
                console.log(total1);

            }   

        }

        else if(dependent25 === "me1s1") {
            for(z=0;z<me1s1.length;z++) {
            if (t_sal > me1s1[z] && t_sal < me1s1[z + 1]) {
                var nearest_number2 = me1s1[z];
                var total2 = ((t_sal - nearest_number2) * status[z-1]) + exception[z-1];
                console.log(total2);

            }   

        }
        else if(dependent25 === "me2s2") {
            for(a=0;a<me2s2.length;a++) {
            if (t_sal > me2s2[a] && t_sal < me2s2[a + 1]) {
                var nearest_number3 = me2s2[a];
                var total3 = ((t_sal - nearest_number3) * status[a-1]) + exception[a-1];
                console.log(total3);

            }   

        }
        else if(dependent25 === "me3s3") {
            for(b=0;b<me3s3.length;b++) {
            if (t_sal > me3s3[b] && t_sal < me3s3[b + 1]) {
                var nearest_number4 = me3s3[b];
                var total4 = ((t_sal - nearest_number4) * status[b-1]) + exception[b-1];
                console.log(total4);

            }
        } 
        else if(dependent25 === "me4s4") {
            for(c=0;c<me4s4.length;c++) {
            if (t_sal > me4s4[c] && t_sal < me4s4[c + 1]) {
                var nearest_number5 = me4s4[c];
                var total5 = ((t_sal - nearest_number5) * status[c-1]) + exception[c-1];
                console.log(total5);

            }
        }

    }
        }
3
Contributors
3
Replies
22
Views
4 Months
Discussion Span
Last Post by JamesCherrill
0

Each "else if" is unclosed brackets. "for" is closed. "if" inside "for" is closed. But "else if" mis-matched

1

Sorry. My English is very bad. Please edit my comments, so I learn to speak correctly.

Well, that English is perfect, no edits needed!

In the post itself... just: Each "else if" has unclosed brackets.

Edited by JamesCherrill

Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.