Uncaught Syntaxerror Error: Unexpected token <=

Asked

Viewed 236 times

0

I am working on a payroll and the function that calculates the IR (income tax) is with some mistake that I honestly am not able to find at all. If anyone can help me.

function desconto_ir()
    {var salario = document.getElementById("salario_bruto").value;
    var inss = document.getElementById("valor_calculado_11").value;
    var esposa = document.getElementById("casado").value;
    var dp1 = document.getElementById("filhos").value;
    var dp2 = document.getElementById("dp_22_24").value;
    var dependentes = eval(esposa + dp1 + dp2);
    var base_de_calculo = (parseFloat(salario - inss - (179.71 * dependentes))).toFixed(2);
    if (base_de_calculo <= 1787.77)
        {document.getElementById("valor_ir").innerHTML = base_de_calculo;}
    else if (base_de_calculo >= 1787.78 && <= 2679.29)
        {document.getElementById("valor_ir").innerHTML = (parseFloat((base_de_calculo * 0.075) - 134.08)).toFixed(2);}
    else if (base_de_calculo >= 2679.30 && <= 3572.43)
        {document.getElementById("valor_ir").innerHTML = (parseFloat((base_de_calculo * 0.15) - 335.03)).toFixed(2);}
    else if (base_de_calculo >= 3572.44 && <= 4463.81)
        {document.getElementById("valor_ir").innerHTML = (parseFloat((base_de_calculo * 0.225) - 602.96)).toFixed(2);}
    else
        {document.getElementById("valor_ir").innerHTML = (parseFloat((base_de_calculo * 0.275) - 826.15)).toFixed(2);}}
  • 1

    What error are you getting? Provide more details about the problem. Use the code in the question instead of a print.

  • Actually the form does not load anymore since I did this function. If I delete it, it returns to function normally. I’ve reviewed all the syntax, the {} and () are closed correctly, the Ids are right... I really can’t find.

  • But what is the error? Calculation error? Data insertion error? When is this function called? Can you debug to see if what you expect is coming? It is this information that is important. Try to improve your issue by providing more information on the issue as detailed as possible.

  • The function is called by a button (onclick). As the form does not load anymore, I do not know if the error is of calculation or insertion, I’m trying to exchange the expressions for others to see if it works... I’m a beginner programmer yet.

  • I put the code here but unfortunately not here Indenta, it was all together.

  • To format the text: http://answall.com/help/formatting

  • 1

    Good night Silas, what mistake appears on the console?

  • Thanks for formatting for me :) So there is no error. The form page no longer loads. If I delete the function, it loads back normally.

  • Sorry I know the question will seem strange, please answer, you know what the console is?

  • I tried to test and in my console appeared error, Uncaught SyntaxError: Unexpected token <=, it is very important you inform this kind of thing when asking.

Show 5 more comments

1 answer

3

Your code is causing

Uncaught Syntaxerror: Unexpected token <=

It has several lines like this && <=, see that after the && is missing a variable, I believe the correct would be:

 } else if (base_de_calculo >= 1787.78 && base_de_calculo <= 2679.29) {

Should stay like this:

function desconto_ir() {
    var salario = document.getElementById("salario_bruto").value;
    var inss = document.getElementById("valor_calculado_11").value;
    var esposa = document.getElementById("casado").value;
    var dp1 = document.getElementById("filhos").value;
    var dp2 = document.getElementById("dp_22_24").value;
    var dependentes = eval(esposa + dp1 + dp2);
    var base_de_calculo = (parseFloat(salario - inss - (179.71 * dependentes))).toFixed(2);

    if (base_de_calculo <= 1787.77) {
        document.getElementById("valor_ir").innerHTML = base_de_calculo;
    } else if (base_de_calculo >= 1787.78 && base_de_calculo <= 2679.29) {
        document.getElementById("valor_ir").innerHTML = (parseFloat((base_de_calculo * 0.075) - 134.08)).toFixed(2);
    } else if (base_de_calculo >= 2679.30 && base_de_calculo <= 3572.43) {
        document.getElementById("valor_ir").innerHTML = (parseFloat((base_de_calculo * 0.15) - 335.03)).toFixed(2);
    } else if (base_de_calculo >= 3572.44 && base_de_calculo <= 4463.81) {
        document.getElementById("valor_ir").innerHTML = (parseFloat((base_de_calculo * 0.225) - 602.96)).toFixed(2);
    } else {
        document.getElementById("valor_ir").innerHTML = (parseFloat((base_de_calculo * 0.275) - 826.15)).toFixed(2);
    }
}
  • Is it still wrong? : the

  • @Danielgomes was just following the example of what I showed that would notice the error elsewhere, see I edited the answer I believe have fixed the whole code.

  • That’s right, haha! You have to repeat the variable name again after &&, now it’s working right! Thanks!!!

  • @Silasrenan I recommend you read: http://meta.pt.stackoverflow.com/q/1078/3635 and http://answall.com/tour

Browser other questions tagged

You are not signed in. Login or sign up in order to post.