mardi 28 juin 2016

Show correct or wrong answer in javascript by if or else statement

I'm working on Javascript and want to show the correct answer when someone clicks on a wrong option. Here is my code

 function processQuestion(choice){
    var bgcolor = '';
    var explanationhtml = '';
    if(quiz.questions[currentquestion]['choices'][choice] == quiz.questions[currentquestion]['correct']){
        bgcolor = '#8AFC7F';
        explanationhtml = '<div class="outcome-headline correct-text"> <i class="glyphicon glyphicon-ok"></i>'+quiz.questions[currentquestion]['correct']+'</div> ';
        score++;
    } else {

        var correct=quiz[currentquestion]['correct'];

    $('li.choice:contains('+correct+')').css('background-color', '#50D943');

         $('.choice').eq(choice).css({
             'background-color': '#D92623'
        explanationhtml = '<div class="alert alert-danger"><div class="outcome-headline incorrect-text"><i class="glyphicon glyphicon-remove"></i><strong>Sorry Wrong Answer!</strong> '+quiz.questions[currentquestion]['correct']+'</div></div> ';

Where did I go wrong?

Aucun commentaire:

Enregistrer un commentaire