0

I'm a newbie. Just coded a simple loan approval application using Javascript with Jquery and Jquery Validation plugins. I'm getting a SyntaxError. - I've matched the beginning and end parens, curly brackets, semicolons and commas and don't understand why its not working. - I've tried different variations and keep getting the error (it points to different code lines with each change). - When I comment out the jQuery Validation code it works so the issue must be with the jQuery Validation code.

Below is code. Currently getting SyntaxError on line 61 which is the last line reflecting --> });

// JavaScript Document // DIAMOND LENDING BANK LOAN APPLICATION

$(document).ready(function() {
    $("#submit").click(function() {
    var salary =  $("#salary").val();   // get salary
    var creditScore = $("#creditScore").val(); // get creditScore
    var monthsJob = $("#monthsJob").val(); // get months at job

    if  (salary >= 40000 && creditScore >= 600) {
        $("#decision").html("Your loan is approved!")
    }
    else if (salary >= 40000 && monthsJob >= 12) {
        $("#decision").html("Your loan is approved!")
    }
    else if (creditScore >= 600 && monthsJob >= 12) {
        $("#decision").html("Your loan is approved!")
    }
    else {
        $("#decision").html("Your loan is declined.")
    };
    return false;
    }); // closes submit.click  

    //     J Q U E R Y    V A L I D A T O R
    $("#loanApp").validate({
        rules: {
            salary: {
            required: true,
            rangelength: [4, 10],
            number: true
            },
            creditScore: {
            required: true,
            rangelength: [3, 3],
            number: true
            },
            monthsJob: {
            required: true,
            rangelength: [1, 3], 
            number: true
            },  
            messages: {
            salary: {
            required: "Please enter your salary.",
            rangelength: "Enter at least 4 numbers and up to 10.",
            number: "Enter numbers only."
            },
            creditScore: {
            required: "Please enter your Credit Score.",
            rangelength: "Credit Scores are 3 numbers long.",
            number: "Enter numbers only."
            },
            monthsJob: {
            required: "Please enter your months at current job.",
            rangelength: "Enter at least 1 number and up to 3.",
            number: "Enter numbers only."
            }
        } 
    }
});
3
  • 1
    You're missing an extra }); at the end there. Commented Oct 26, 2016 at 14:00
  • 1
    And another example where proper indentation helps... :) Commented Oct 26, 2016 at 14:02
  • I'll try that next time. Thanks! Commented Oct 27, 2016 at 0:23

4 Answers 4

0

You lack another }); at the very end for your $(document).ready(.... The current one is for the $(#loanApp).validate(...

Sign up to request clarification or add additional context in comments.

Comments

0

You've made a little indentation error, which caused you to miss a curly brace for your document.ready():

            }
        } 
    }
});

Should be:

                }
            } 
        }
    });
});

Comments

0

You're missing an extra }); at the end there. Add that and everything should work fine.

$(document).ready(function() {
    $("#submit").click(function() {
    var salary =  $("#salary").val();   // get salary
    var creditScore = $("#creditScore").val(); // get creditScore
    var monthsJob = $("#monthsJob").val(); // get months at job

    if  (salary >= 40000 && creditScore >= 600) {
        $("#decision").html("Your loan is approved!")
    }
    else if (salary >= 40000 && monthsJob >= 12) {
        $("#decision").html("Your loan is approved!")
    }
    else if (creditScore >= 600 && monthsJob >= 12) {
        $("#decision").html("Your loan is approved!")
    }
    else {
        $("#decision").html("Your loan is declined.")
    };
    return false;
    }); // closes submit.click  

    //     J Q U E R Y    V A L I D A T O R
    $("#loanApp").validate({
        rules: {
            salary: {
            required: true,
            rangelength: [4, 10],
            number: true
            },
            creditScore: {
            required: true,
            rangelength: [3, 3],
            number: true
            },
            monthsJob: {
            required: true,
            rangelength: [1, 3], 
            number: true
            },  
            messages: {
            salary: {
            required: "Please enter your salary.",
            rangelength: "Enter at least 4 numbers and up to 10.",
            number: "Enter numbers only."
            },
            creditScore: {
            required: "Please enter your Credit Score.",
            rangelength: "Credit Scores are 3 numbers long.",
            number: "Enter numbers only."
            },
            monthsJob: {
            required: "Please enter your months at current job.",
            rangelength: "Enter at least 1 number and up to 3.",
            number: "Enter numbers only."
            }
        } 
    }
});

});//this is missing from your code, add this

Comments

0

Missing a }); at the end.

Looks like the missing tab between messages and salary is messing you up from a visual perspective.

$(document).ready(function() {
    $("#submit").click(function() {
    var salary =  $("#salary").val();   // get salary
    var creditScore = $("#creditScore").val(); // get creditScore
    var monthsJob = $("#monthsJob").val(); // get months at job

    if  (salary >= 40000 && creditScore >= 600) {
        $("#decision").html("Your loan is approved!")
    }
    else if (salary >= 40000 && monthsJob >= 12) {
        $("#decision").html("Your loan is approved!")
    }
    else if (creditScore >= 600 && monthsJob >= 12) {
        $("#decision").html("Your loan is approved!")
    }
    else {
        $("#decision").html("Your loan is declined.")
    };
    return false;
    }); // closes submit.click  

    //     J Q U E R Y    V A L I D A T O R
    $("#loanApp").validate({
        rules: {
            salary: {
            required: true,
            rangelength: [4, 10],
            number: true
            },
            creditScore: {
            required: true,
            rangelength: [3, 3],
            number: true
            },
            monthsJob: {
            required: true,
            rangelength: [1, 3], 
            number: true
            },  
            messages: {
                salary: {
                required: "Please enter your salary.",
                rangelength: "Enter at least 4 numbers and up to 10.",
                number: "Enter numbers only."
                },
                creditScore: {
                required: "Please enter your Credit Score.",
                rangelength: "Credit Scores are 3 numbers long.",
                number: "Enter numbers only."
                },
                monthsJob: {
                required: "Please enter your months at current job.",
                rangelength: "Enter at least 1 number and up to 3.",
                number: "Enter numbers only."
                }
            } 
        }
    });
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.