jquery匹配随机数后增加分数

时间:2016-02-27 16:06:42

标签: jquery if-statement increment

我一直试图弄清楚每次在随机数匹配后点击按钮或不匹配时如何进行增量。

基本上,如果数字匹配,匹配的计数器将会增加。数据不匹配也是如此。

但目前,该计数器只会上升一次而且只会上升一次。

jQuery的:

haproxy 127.0.0.1:8080   =>  127.7.102.2:8080
haproxy 127.0.0.1:8081   =>  127.7.102.3:8080
mongodb 127.0.0.1:37986  =>  56cf022d0c1e6642dd000142-hackthroneht.rhcloud.com:37986
node    127.0.0.1:8082   =>  127.7.102.1:8080

2 个答案:

答案 0 :(得分:0)

correct在函数addScore中是本地的。它每次都会增加,但每次都会设置为0。您需要在该功能之外放置correctwrong

var correct = 0;
var wrong = 0;

function addScore(){
    if (a == b){
        correct++;
        $("#correctScore").html(correct);
    }else{
        wrong++;
        $("#wrongScore").html(wrong);    
    }
}

答案 1 :(得分:0)

public class Test {

public static void main(String[] args) {
    cyclometricComplexityTest();
}

static boolean cond1 = true;
static boolean cond2 = true;
static boolean cond3 = true;
static boolean cond4 = true;
static boolean cond5 = true;

public static Object cyclometricComplexityTest() {
    if (isBoolean1()) {
        // actions to perform
        Object result = null;
        calculateValues();
        return result;
    } else if (isBoolean2()) {
        // actions to perform
        Object result = new Result();
        return result;
    } else if (isBoolean3()) {
        // actions to perform
        Object result = new Result();
        return result;
    } else {
        throw new RuntimeException();
    }
}

static boolean isBoolean1() {
    return !cond3 && !cond1 && cond2 && cond4;
}

private static boolean isBoolean2() {
    return !cond1 && cond2 && cond3;
}

private static boolean isBoolean3() {
    return !cond4 && cond3 && cond1 && cond5;
}

static void calculateValues() {}

static class Result {}
}
相关问题