数学阵列作业问题编码javascript?

时间:2013-04-21 23:40:27

标签: javascript math

这就是我所拥有的但我需要记录错误的问题并让用户回答它们直到正确,继续提示用户问题,直到它正确这是一个4部分问题而第3部分是同样的问题重复直到完成

ex。(7 + 1 = 6)重复(7 + 1 = 4)重复(7 + 1 = 8)下一个问题 用户必须完成5个问题并且必须正确

    <html>
    <script>
var file=0;
var fileIndex=new Array();
var user=prompt("what is "+a+" + "+b);
var arr=[user,user,user,user,user];
var a=Math.floor(Math.random()*11);
var b=Math.floor(Math.random()*11);
var answer=parseInt(a+b);
var user=prompt("what is "+a+" + "+b);


while (user != answer && file++ != 4) {
fileIndex.push(user);
user = prompt("what is " + a + "+" + b);
 } else {
alert("answer is:" + answer);
 }

}//close for

</script>

1 个答案:

答案 0 :(得分:0)

更新

var a = 1,
    b = 1;

var answer = a + b,
    tick = 0;

var file_index = [], copy;

function randomize() {
    a = Math.floor(Math.random() * 11);
    b = Math.floor(Math.random() * 11);

    answer = a + b;
}

while (1)
{
    if ((copy = prompt("What is " + a + " + " + " b?", 0)) != answer)
    {
        if (!copy) break;
        file_index.push(copy);
        randomize();
    } else if (tick == 4) {   
        break;
    } else {
        ++tick;
    }
}

jsFiddle Demo