变量不会改变if语句

时间:2016-10-17 21:04:47

标签: javascript

我正在研究网站的代码,我正在尝试接收输入,并根据输入显示特定的消息。每当我输入一个数字时,它会被设置为第一个if结果。任何帮助都会很棒,谢谢

ValueError: [ 0  1  2  3  5  6  7  8 10 11 12 13 14 16 17 18 19 20 21 22 23] not contained in the index

2 个答案:

答案 0 :(得分:0)

你在这里分配价值..

if(b = 2){

它应该是..

if(b == 2){

答案 1 :(得分:-1)

嘿,将其改为以下

function testCheck(){ 
  var a = parseFloat(document.getElementById("tookTests").value);
  var b = a;
  var c;

  if (b == 2 ) {
    c = "Yes you can! You've earned it.";
    } else if (b == 1) {
    c = "You need to keep studying then";
    } 
    else if (b > 2 ) {
    c = "That's more tests than you're supposed to have";
    }else {
    c = "Why are you on here? You need to study.";
}

 document.getElementById("change").innerHTML = c;
}