function displayScore() {
        var score = $('<p class="score">', {id: 'question'});

        $.get("/questions/validate?level=" + level, function (data) {
            if (data) {

                var numCorrect = 0;
                for (var i = 0; i < selections.length; i++) {
                    console.log(selections[i] + "    " + data[i].answer);
                    if (selections[i] === data[i].answer) {
                        numCorrect++;
                    }
                }

                score.html('Hey ' + $('#userName').val() + '! You got ' + numCorrect + ' questions out of ' +
                    questions.length + ' right!!!');
                quiz.append(score).fadeIn();

                if (numCorrect == questions.length) {
                    $('#success_img').fadeIn();
                }

                $.ajax({
                    contentType: 'application/json',
                    data: JSON.stringify({ "user": $('#userName').val(), "count":numCorrect }),
                    dataType: 'json',
                    success: function(data){
                        console.log("Record saved!");
                    },
                    error: function(){
                        console.log("Recording failed");
                    },
                    processData: false,
                    type: 'POST',
                    url: '/questions/user/report'
                });

                $('#start').show();


            } else {
                alert('Error occurred when validating!')
                return 0;
            }
        });
    }
// Computes score and returns a paragraph element to be displayed
Computes score and returns a paragraph element to be displayed
Computes score and returns a paragraph element to be displayed
function displayScore() {
        var score = $('<p class="score">', {id: 'question'});
        $.get("/questions/validate?level=" + level, function (data) {
            if (data) {
                var numCorrect = 0;
                for (var i = 0; i < selections.length; i++) {
                    console.log(selections[i] + "    " + data[i].answer);
                    if (selections[i] === data[i].answer) {
                        numCorrect++;
                    }
                }
                score.html('Hey ' + $('#userName').val() + '! You got ' + numCorrect + ' questions out of ' +
                    questions.length + ' right!!!');
                quiz.append(score).fadeIn();
                if (numCorrect == questions.length) {
                    $('#success_img').fadeIn();
                }
                $.ajax({
                    contentType: 'application/json',
                    data: JSON.stringify({ "user": $('#userName').val(), "count":numCorrect }),
                    dataType: 'json',
                    success: function(data){
                        console.log("Record saved!");
                    },
                    error: function(){
                        console.log("Recording failed");
                    },
                    processData: false,
                    type: 'POST',
                    url: '/questions/user/report'
                });
                $('#start').show();
            } else {
                alert('Error occurred when validating!')
                return 0;
            }
        });
    }
function displayScore ( ) { var score = $ ( '<p class="score">' , { id : 'question' } ) ; $ . get ( "/questions/validate?level=" + level , function ( data ) { if ( data ) { var numCorrect = 0 ; for ( var i = 0 ; i < selections . length ; i ++ ) { console . log ( selections [ i ] + "    " + data [ i ] . answer ) ; if ( selections [ i ] === data [ i ] . answer ) { numCorrect ++ ; } } score . html ( 'Hey ' + $ ( '#userName' ) . val ( ) + '! You got ' + numCorrect + ' questions out of ' + questions . length + ' right!!!' ) ; quiz . append ( score ) . fadeIn ( ) ; if ( numCorrect == questions . length ) { $ ( '#success_img' ) . fadeIn ( ) ; } $ . ajax ( { contentType : 'application/json' , data : JSON . stringify ( { "user" : $ ( '#userName' ) . val ( ) , "count" : numCorrect } ) , dataType : 'json' , success : function ( data ) { console . log ( "Record saved!" ) ; } , error : function ( ) { console . log ( "Recording failed" ) ; } , processData : false , type : 'POST' , url : '/questions/user/report' } ) ; $ ( '#start' ) . show ( ) ; } else { alert ( 'Error occurred when validating!' ) return 0 ; } } ) ; }
Computes score and returns a paragraph element to be displayed
Computes score and returns a paragraph element to be displayed