Javascript' TypeError:字符串不是函数'

时间:2017-03-23 13:47:28

标签: javascript

这是在applab上运行的,我的代码第55行给出了错误。它说TypeError:string不是一个函数。我似乎无法弄清楚它所处的功能或上面代码中的某个地方是否运行不正常,如果有人可以看一看就会非常感激问题是什么



onEvent("startButton", "click", function() { 
  setScreen("safeScreen");
  endGame();
});//changes to the main games screen,after 2 minutes ends game
onEvent("retryButton", "click", function() { 
  setScreen("welcomeScreen");
});// changes screen to welcome screen from win screen
onEvent("againButto", "click", function() {
  setScreen("welcomeScreen");
});//changes screen to welcome screen from lose screen

function endGame(){
  setTimeout(function(){
    setScreen("loseScreen");
  },120000);
}
var input1=0;
setText("comboDisplay1",input1);//sets display1 to 0
var input2=0;
setText("comboDisplay2",input2);//sets display2 to 0
var input3=0;
setText("comboDisplay3",input3);//sets display3 to 0
onEvent("upButton1", "click", function(){
  input1 = input1 + 1;
  setText("comboDisplay1",input1);
});//when up button1 is pressed the number display changes
onEvent("upButton2", "click", function(){
  input2= input2 + 1;
  setText("comboDisplay2",input2);
});//when up button2 is pressed the number display changes
onEvent("upButton3", "click", function(){
  input3= input3 + 1;
  setText("comboDisplay3",input3);
});//when up button3 is pressed the display changes
onEvent("downButton1", "click", function(){
  input1 = input1 - 1;
  setText("comboDisplay1",input1);
});//when down button1 is pressed the number display changes
onEvent("downButton2", "click", function(){
  input2 = input2 - 1;
  setText("comboDisplay2",input2);
});//when down button2 is pressed the number display changes
onEvent("downButton3", "click", function(){
  input3 = input3 - 1;
  setText("comboDisplay3",input3);
});//when down button3 is pressed the number display changes

var playerInput;
var combination;
combination = [randomNumber(0,9),randomNumber(0,9),randomNumber(0,9)];//generates a random list of 3 numbers from 0 to 9
console.log(combination);

playerInput += getText("comboDisplay1","comboDisplay2","comboDisplay3");//assings the display numbers to the variable playerInput
function yellowLight() {
  if (getNumber("comboDisplay1") != combination(0)) {
    if (getNumber("comboDisplay1") == (combination(1)||combination(2))) {
      showElement("yellowLight1");
    }
  }
  if (getNumber("comboDisplay2") != combination(1)) {
    if (getNumber("comboDisplay2") == (combination(0) || combination(2))) {
      showElement("yellowLIght2");
    }
  }
  if (getNumber("comboDisplay3") != combination(3)) {
    if (getNumber("comboDisplay3") == (combination(0) || combination(1))) {
      showElement("yellowLight3");
    }
  }
}
function greenLight(){
  if(getNumber("comboDisplay1") == combination(0));
    showElement("greenLight1");
  if(getNumber("comboDisplay2") == combination(1));
    showElement("greenLight2");
  if(getNumber("comboDisplay3") == combination(2));
    showElement("greenLight3");
}
//checks and shows a green light if the number is correct and in the right place
onEvent("submitButto", "click", function(){
  if( playerInput== combination){
    greenLight();
  }
    yellowLight();
});




1 个答案:

答案 0 :(得分:1)

combination的类型是数组。您必须使用[]访问其元素,而不是(),例如combinations[0]