Kickstarting while循环javascript(同时使用jquery)

[英]Kickstarting while loop in javascript(while using jquery)


Hello i am currently learning javascript and trying to make a simple game with it,when i click ENTER button on my keyboard it should start the game,as you see game_mode would be 1,then while loop should start printing "working",for me to know that it's looping but somewhy,when game_mode becomes 1 the loop doesnt start,why is this happening?I am using this loop in

您好我正在学习javascript并试图用它做一个简单的游戏,当我点击键盘上的ENTER按钮它应该启动游戏,因为你看到game_mode将是1,然后while循环应该开始打印“工作”,对我来说要知道它正在循环但有些为什么,当game_mode变为1时,循环无法启动,为什么会发生这种情况?我正在使用这个循环

$(document).ready(function())

Because of jquery.

因为jquery。

P.S i know that it would loop forever,i just need to see it loop.Thank you for your time

P.S我知道它会永远循环,我只需要看它循环。谢谢你的时间

  while(game_mode===1)
    {
     
      alert("working");
    }
    $(document).keydown(function(event){ //For moving keys
      if(game_mode===1)
      {
        moveKeys();
      }
      if(event.which===13)          //IF ENTER IS PRESSED
      {
        if(game_mode===0)
        {
          game_mode+=1;
          $("#phase_mode").text("Started");
        }else if(game_mode==1)
        {
          $("#phase_mode").text("Paused");
          game_mode+=1;
        }else
        {
            $("#phase_mode").text("Started");
            game_mode-=1;
        }
      }
    });

1 个解决方案

#1


0  

You should put the while loop inside the if(game_mode===0) condition if you want it to alert "working" message, But really you should not do that, because you will create an infinite loop that will crash your app/browser.

你应该将if循环放在if(game_mode === 0)条件中,如果你想让它提醒“工作”消息,但实际上你不应该这样做,因为你会创建一个无限循环,会使你的应用程序/浏览器崩溃。

智能推荐

注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:http://www.itdaan.com/blog/2015/12/25/3a6596ec074afa923a820eda17f478be.html



 
© 2014-2019 ITdaan.com 粤ICP备14056181号  

赞助商广告