-1

design file

<design:component>
    <design:attribute name="questionText" label="Question Text"
                      description="Provide the question text here." />
    <design:attribute name="answers" label="Possible Answers"
                      description="Provide the potential answers (yes:true,no:false for example) here." />
</design:component>

Controller file

({  

    handleAnswer : function(component, event, helper) {
        var validity = helper.handleAnswer(event);
        action.setParams({
            "validity" : event.getSource().get("v.value"),
            "selectedQuestion" : component.get("v.Question")
        });
        action.setCallback(this, function(response) {
            if ( validity == 'true' )
                var sMsg = 'Valid';                
            var toastEvent = $A.get("e.force:showToast");
            toastEvent.setParams({
                mode: 'dismissible',
                duration:' 5000',
                message: sMsg,
                type : 'success'
            });
            toastEvent.fire();
        }
        else if ( validity == 'false' );
        var errors = response.getError();
        if (errors) {
            if (errors[0] && errors[0].message) {
                var sMsg = errors[0].message;                
                var toastEvent = $A.get("e.force:showToast");
                toastEvent.setParams({
                    mode: 'dismissible',
                    duration:' 5000',
                    message: sMsg,
                    type : 'error'
                });
                toastEvent.fire();
            }
        }
        else
            component.set("v.message", 'Invalid' );
    }
}
});
        $A.enqueueAction(action);
    },
    alert('something went wrong ' + validity);
}

})
({
    doInit : function(component, event, helper) {
        helper.getAnswers(component);
    },

Helper

    ({
    getAnswers : function(component) {
        var answersList  = component.get("v.answers");
        var answerObjects    =             [];
        answersList  = answersList.split(',');


        for (var i = 0; i < answersList.length; i++){
            var answers = answersList[i].split(':');
            var answerObject = {answerLabel:answers[0], answerValidity:answers[1]};
            answerObjects.push(answerObject);
            console.log(i + ' answer is ' + answers[0] + ' validity is ' + answers[1]);
        }
        component.set('v.answerObjects', answerObjects);
        console.log(answerObjects);
    },

    handleAnswer : function(event) {
        var validity = event.getSource().get("v.value").trim().toLowerCase();
        console.log(validity);
        return validity;
    }
})

closed as unclear what you're asking by battery.cord, glls, codeyinthecloud, Pranay Jaiswal, Reshma Jan 10 at 6:06

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 3
    You will find your work dramatically easier if you (1) always use curly braces around every single block (including if/else), and (2) utilize a JavaScript formatter to indent your code correctly. This is a pretty simple syntax error stemming from a missing bracket. – David Reed Jan 9 at 20:14
  • 1
    Jeff, I don't see an actual question. Please take the time to read How to Ask. Thanks – Robs Jan 9 at 20:17
  • @DavidReed which JavaScript formatter does a Ninja like you recommend? – Robs Jan 9 at 20:17
  • @Robs I am emphatically not a JavaScript ninja - my JS is workmanlike at best - but I've had success with the built-in format support in Visual Studio Code. Perhaps someone with more front-end experience can speak to the toolchain! – David Reed Jan 9 at 20:24
  • @DavidReed I use the builtin one too. Was just curious. – Robs Jan 9 at 20:26
2

You have several important syntax errors, and I'm not going to go through and correct the code line-by-line but simply point out the classes of issues here and how to start correcting them.

At

        if ( validity == 'true' )

you are missing an open bracket for this block. You should make a point of always bracketing your blocks. It is far too easy to make mistakes about the scope of a conditional, since it's legal to place a single statement after a conditional without braces.

You are similarly missing a bracket, and have an extra semicolon, at

    else if ( validity == 'false' );

While it is syntactically valid, you should use braces at

    else
        component.set("v.message", 'Invalid' );

As a consequence of these issues and your issues with indenting, which may stem from poor brace structure, your closing brackets and parenthesis for the callback, call to $A.enqueueAction, and controller function are disordered and need to be checked when you correct your other issues.

Not the answer you're looking for? Browse other questions tagged or ask your own question.