خرید بک لینک

Vote count: 0

The link to my pen in CodePen - http://codepen.io/PartTimeCoder/pen/WwMxEX?editors=0010

The Javascript is here:

function randomNum(digits) {
    retu Math.floor(Math.pow(10, digits - 1) + Math.random() * 9 * Math.pow(10, digits - 1));
}

function askQuestion(digits) {
    $(".result").html("");

    var factor1 = randomNum(digits);
    var factor2 = randomNum(digits);
    var correctanswer = factor1 * factor2;
    var answer = parseInt($(".answer").val(), 10);

    console.log(correctanswer);

    $(".question").html(factor1 + " × " + factor2);

    var score = 0;

    //Problem Starts Here
    $(".check").click(function() {
        if (correctanswer == answer) {
            $(".result").html("Correct");
            score += 1;
            $(".score").html(score);
            askQuestion(digits);
        } else {
            $(".result").html("Wrong");
            score -= 1;
            $(".score").html(score);
        }
    });
    //Problem Ends Here
}

$(document).ready(function() {
    $(".answer").hide();
    $(".check").hide();

    var digits = 0;

    $(".digits-1").click(function() {
        digits += 1;
    });

    $(".digits-2").click(function() {
        digits += 2;
    });

    $(".digits-3").click(function() {
        digits += 3;
    });

    $(".btn").click(function() {
        $(".btn").hide();
        $(".answer").show();
        $(".check").show();
        askQuestion(digits);
    });
});

In between the Idea is where I think the problem is. For example when it asks 4 x 9 and i input 36, it still marks it as wrong. I don't know why this is doing this. At first I though that the inputted information might still be a string so I used parseInt on it and it still didn't work. All help is appreciated. Thanks in advance!

asked 50 secs ago

برچسب: نویسنده: استخدام کار تاريخ: دوشنبه 23 فروردين 1395 ساعت: 4:43

صفحه بندی