首页 > 解决方案 > 脚本中的结构我相信我错了。有耐心,我正在尝试将我的编码组织到我更好理解的地方

问题描述

这是 Simon 用 javascript 说的一个项目,我一直在花时间研究这个项目,以便我可以更好地理解逻辑,当我编写代码时,我将能够肯定地解释和理解。

这是 Chrome 上 Web 控制台中的代码输出: Web 控制台的屏幕截图

在控制台日志中,我的输出为 5,但是,当您仔细查看代码 5 输出“index.html 61:3”的右侧时,index.html 之前的椭圆形数字 95。

这从 5 开始并继续添加 5,现在达到 95。

我一直在练习完善任何输入的编码将很有帮助。这是我的代码:

    <!DOCTYPE html>
    <head>
    <meta charset="UTF-8">
    <meta name="keywords" content="HTML, CSS, XML, XHTML, JavaScript">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" type="text/css" href="style.css">
    <script src="https://code.jquery.com/jquery-3.1.1.slim.min.js" integrity="sha384-A7FZj7v+d/sdmMqp/nOQwliLvUsJfDHW+k9Omg/a/EheAdgtzNs3hpfag6Ed950n" crossorigin="anonymous"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/tether/1.4.0/js/tether.min.js" integrity="sha384-DztdAPBWPRXSA/3eYEEUWrWCy7G5KFbe8fFjk5JAIxUYHKkDx6Qin1DkWx51bBrb" crossorigin="anonymous"></script>
    </head>
    <body>
    <h2 id="clickNumber">0</h2>
      <button id="red1" class="colors" onclick="red()"></button>
      <button id="blue1" class="colors" onclick="blue()"></button>
      <button  id="green1" class="colors" onclick="green()"></button>
      <button id="yellow1" class="colors" onclick="yellow()"></button>
    <script>
    //
    simonArr=[];
      simonArr[0] = red;
      simonArr[1] = blue;
      simonArr[2] = green;
      simonArr[3] = yellow;
      simonAr = [
       document.getElementById('red1'), document.getElementById('blue1'),                            
       document.getElementById('green1'), document.getElementById('yellow1')
      ];


    function red(){
     document.getElementById('red1').style.opacity = ".25";
       setInterval( function(){
           document.getElementById('red1').style.opacity = "1";
          }, 3000);
    }

    function blue(){
    document.getElementById('blue1').style.opacity = ".25";
    setInterval( function(){
           document.getElementById('blue1').style.opacity = "1";
          }, 3000);
    }
    function green(){
    document.getElementById('green1').style.opacity = ".25";
    setInterval( function(){
           document.getElementById('green1').style.opacity = "1";
          }, 3000);
    }
    function yellow(){
    document.getElementById('yellow1').style.opacity = ".25";
    setInterval( function(){
           document.getElementById('yellow1').style.opacity = "1";
          }, 3000);

    }


    var mySimon = setInterval(simonMix, 2000);
    var simonX = simonAr.push(Math.floor(Math.random()*simonAr.length)+1);

    function simonMix(){
    for(var i=0;i<simonAr.length;i++){
       if(simonX[i].style.opacity = ".25"===-1){
    simonX[i].style.opacity ="1";   
  };
      console.log(simonX)

      }
    }



    </script>
    </body>
    </html>

标签: javascripthtmlcss

解决方案


推荐阅读