错误:意外的令牌功能

时间:2017-04-02 17:43:21

标签: javascript jquery html css

我正在制作序列游戏,过去一小时我一直收到此错误Uncaught SyntaxError: Unexpected token function

我首先想到的是,在阅读了一些StackOverFlow消息后,我可能没有正确地关闭我的文件?然而,低,看,我仍然无法弄清楚。

我是新手编码所以和我在一起:)

HTML

<body>
<div class="row">
<div class="col-md-12">
<div class="gamefield">
<div class="top-row">
<div id="blue" class="gamebutton"></div>
</div>
<div class="middle-row">
<div id="green"  class="gamebutton"></div>
<div id="gameNumber">
<h2 id="clickNumber">0</h2></div>
<div id="red" class="gamebutton"></div>
</div>
<div class="bottom-row">
<div id="dark" class="gamebutton"></div>
<div>
</div>
</div>
</div>
</div>
</div>

</body>
</html>

JS

$(document).ready(function(e){
console.log('hello');


var game = {
count: 0,
possibilities: ['#green','#blue', '#red', '#dark'],
currentGame: [],
player: [],
playGame:


game.clearGame = function clearGame() {
  game.currentGame = [];
  game.count = 0;
  addCount();
}

 function newGame() {
  clearGame();
}

game.Strict = function strict() {
  if (game.strict === false) {
    game.strict === true;
    $('#strict').html('Is currently On').removeClass('btn-primary').addClass('btn-danger');
  } else {
    game.strict = false;
    $('#strict').html('Is currently Off').removeClass('btn-danger').addClass('btn-primary');
  }

  newGame();
}

game.ShowMoves = function showMoves() {
  var i = 0;
  var moves = setInterval(function(){
    playGame(game.currentGame[i]);
    i++;
    if (i >= game.currentGame.length) {
      clearInterval(moves);
    }
  }, 600)

  clearPlayer();
}

Game.Shade = function shade(name) {
  switch(name) {
    case'#green':
      game.shade.green.show();
      break;
    case '#blue':
      game.shade.blue.show();
      break;
    case '#red':
      game.shade.red.show();
      break;
    case '#dark':
      game.shade.dark.show();
      break;
  };
}

game.playGame = function playGame(field) {
  $(field).addClass('hover');
  shade(field);
  setTimeout(function(){
      $(field).removeClass('hover');
  }, 300);
}

game.clearPlayer = function clearPlayer() {
  game.player = [];
}

game.addToPlayer = function addToPlayer(id) {
  var field = "#"+id
  console.log(field);
  game.player.push(field);
  playerTurn(field);
}

game.playerTurn = function playerTurn(x) {
  if (game.player[game.player.length - 1] !== game.currentGame[game.player.length - 1]) {
    if(game.strict){
      alert('Sorry not right');
      newGame();
    } else {
      alert('Wrong!');
      showMoves();
    }
   } else {
      shade(x);
      var check = game.player.length === game.currentGame.length;
      if (check) {
        if(game.count === 20){
          alert('Aced it!');
        } else {
          alert('Nice one, new round');
          nextLevel();
        }
      }
    }
}

game.nextLevel = function nextLevel() {
  addCount();
}

game.generateMove = function generateMove(){
  game.currentGame.push(game.possibilities[(Math.floor(Math.random()*4))]);
  //alert(game.currentGame.length);
  showMoves();
}

game.addCount = function addCount() {
  game.count++;
  $('#clickNumber').addClass('animated fadeOutDown');

  setTimeout(function(){
    $('#clickNumber').removeClass('fadeOutDown').html(game.count).addClass('fadeInDown');
  }, 200);

  generateMove();
}

newGame();
});

任何想法都会成为王牌。

1 个答案:

答案 0 :(得分:0)

var game = {
count: 0,
possibilities: ['#green','#blue', '#red', '#dark'],
currentGame: [],
player: [],
playGame:

您可能希望像这样关闭对象:

var game = {
count: 0,
possibilities: ['#green','#blue', '#red', '#dark'],
currentGame: [],
player: [],
playGame:
}

同样gameGame不同。所以也要修复Game.Shade。同时保持代码正确缩进和格式化。帮助抵御任何明显的错误错误。