简体   繁体   English

谁能指出我在这里的错误我找不到它

[英]Could anyone point to me the error here i can't find it

So this is my last task for FreeCodeCamp, i've asked on the chat room but nobody could point me the error. 所以这是我对FreeCodeCamp的最后一项任务,我在聊天室问过,但没人能指出我的错误。 The problem is that the pattern the computer plays starts with the last element, then goes from start to finish, repeating the last element, which is confusing for the player. 问题在于计算机播放的模式从最后一个元素开始,然后从头到尾重复执行最后一个元素,这对播放器造成了困扰。

$(document).ready( function() {

  var gamestarted = false;
  var arrTones = []; // track all game tones from the begining
  var arrPlayer = []; // track all user tones played
  var arrComp = []; // track all comp tones played
  var steps = null;
  var playerTurns = null;
  var strict = null;

  function playAudio(id) {
    var audio = 'audio' + id ;
    audio = document.getElementById(audio);
    audio.play();
  }

  $('.audio').click(function () {
    var id = Number( $(this).attr('id') );
    playAudio(id);
    if(gamestarted) {
      arrPlayer.push(id);
      if ( arrPlayer[playerTurns] != arrComp[playerTurns] ) {
        if(strict) {
          alert('Start a new game');
          setTimeout( start, 1000 );
        } else {
          alert('Here is the pattern again');
          setTimeout( nextstep, 1000 );
        }
      } else if ( arrPlayer.length < arrComp.length ) {
        playerTurns++;
      } else if ( arrPlayer.length == arrComp.length && steps < 20) {
        steps++;
        setTimeout( nextstep , 1000);

      }

    }
  });

  function start() {

//     reset of all arrays and the steps
    arrTones = [];
    arrPlayer = [];
    arrComp = [];
    steps = 0;
    gamestarted = true;
    strict = $('#strict').prop('checked');

//     generate all moves for this game
    for (var i=1; i<=20; i++) {
      val = Math.floor(Math.random() * (4 - 1 + 1) + 1);
      arrTones.push(val);
    }

//     get first comp move
    nextstep();

  }

  $('#start').click(function () {
    start();        
  });  

  function nextstep() {

    var tones = 0;

    arrComp = [];
    for (var x=0; x<=steps; x++) {
      arrComp.push(arrTones[x]);
    }

    var moves = setInterval(function() {

      compTurn(arrComp[tones]);

      tones++;

      if ( tones >= arrComp.legth ) {
        clearInterval(moves);
      }

    }, 1000);

    playerTurn();
  }

  function compTurn(id) {
    var button = '#'+id;
    $(button).addClass('btn-outline-secondary');
    playAudio(id);
    setTimeout( function () {
      $(button).removeClass('btn-outline-secondary');
    }, 300);
  }

  function playerTurn() {
    arrPlayer = [];
    playerTurns=0;
  }

});

Here is the codepen code for this Simon Game 这是此西蒙游戏的codepen代码

You have misspelled property name 'length' 您拼写了属性名称“ length”

if ( tones >= arrComp.legth ) {
    clearInterval(moves);
  }

change it to arrComp.length it will work. 将其更改为arrComp.length它将起作用。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我正在制作导航栏,但我没有发现响应此导航栏的错误。 谁能帮我 - I am making nav bar but I don't find the error in making responsive to this nav bar. Can anyone help me 运行main.js时出现错误。 “找不到模块&#39;app&#39;”。 谁能帮我 - I'm getting an error while running main.js. “ Cannot find module 'app' ”. Could anyone help me out 试图抓住输入值并显示,谁能告诉我我在这里做错了什么? - Trying to grap the input value and display, Can anyone tell me what i'm doing wrong here? 我尝试创建一个图像弹出窗口但在这里我的脚本严重失败任何人都可以帮助我 - I tried creating a image popup but failed badly here my script anyone can help me out 谁能让我知道为什么会收到此错误? - Can anyone let me know why am I getting this error? 谁能告诉我这个简单的代码有什么问题? - Can anyone tell me whats wrong here in this simple code? 我创建了这个下拉框,但项目没有被选中。 我在这里留下我的代码,有人可以帮助我吗? - I created this dropdown box but the items are not getting selected. I am leaving my code here, can anyone help me out? 我通过 npm start 启动了我的开发服务器,然后遇到了这个错误任何人都可以帮我解决这个问题 - I started my development server by npm start and then encountered this error anyone could help me fix this Please 谁能帮我解决这个反应错误? - can anyone help me with this react error? 我遇到两个错误,有人可以帮助我找到它们吗? - I am getting two errors, Can anyone help me find them?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM