Home > front end >  Why doesn't my js statements made
Why doesn't my js statements made

Time:10-18




<meta charset="utf-8">
Snake & lt;/title> <br/><style> <br/>The body <br/>{display: flex; justify-content: center; align-items: center; } <br/></style> <br/></head> <br/><body> <br/><Canvas> Id="can" width="400" height="400" style="background - color: red" & gt; Does not support canver</canvas> <br/><The script type="text/javascript" & gt; <br/>Var snake=[200199] direction=1, the food=201, n. <br/>Var box=document. GetElementById () 'can'. GetContext (" 2 d "); The function the draw (seat, color) {<br/>Box. FillStyle=color; <br/>Box. FillRect (seat % 20 * 20 + 1, ~ ~ (20) seat/* 20 + 1,18,18); } the for (I=0; i<=399; I++) <br/>{the draw (I, "black"); } <br/>Document. The onkeydown=function (evt) {direction=snake [1] - snake [0]==(n=20,1,20] [- 1 - [(evt | | event). The keyCode to 37] | | direction)? Direction: n. }; <br/>! The function () {snake. Unshift (n=snake [0] + direction); If (snake. IndexOf (n, 1) & gt; 0 | | n<0 | | n> 399 | | direction==1 & amp; & N % 20==0 | | direction==1 & amp; & N % 20==19) <br/>{return alert (" GAME OVER "); } <br/>The draw (n, "lime"); <br/>If (n==food) while (snake. IndexOf (food=~ ~ (Math) random () * 400)) & gt; 0); The draw (food, "yellow"); } <br/>The else {the draw (snake. Pop (), "black"); } setTimeout (the arguments. The callee, 150); } (); <br/></script> <br/></body> <br/></html><p class="article - content rp"> CodePudding user response: </p><! DOCTYPE html> <html> <br/><head> <meta charset="utf-8"> <br/><title> Snake & lt;/title> <br/><style> <br/>{display: flex; justify-content: center; align-items: center; } <br/></style> <br/></head> <body> <br/><Canvas> Id="can" width="400" height="400" style="background - color: red" & gt; Does not support canver</canvas> <br/><The script type="text/javascript" & gt; <br/>Var snake=[200199] direction=1, the food=201, n. <br/>Var box=document. GetElementById () 'can'. GetContext (" 2 d "); The function the draw (seat, color) {<br/>Box. FillStyle=color; <br/>Box. FillRect (seat % 20 * 20 + 1, ~ ~ (20) seat/* 20 + 1,18,18); } the for (I=0; i<=399; I++) <br/>{the draw (I, "black"); } <br/>Document. The onkeydown=function (evt) {direction=snake [1] - snake [0]==(n=20,1,20] [- 1 - [(evt | | event). The keyCode to 37] | | direction)? Direction: n. }; <br/>! The function () {snake. Unshift (n=snake [0] + direction); If (snake. IndexOf (n, 1) & gt; 0 | | n<0 | | n> 399 | | direction==1 & amp; & N % 20==0 | | direction==1 & amp; & N % 20==19) <br/>{return alert (" GAME OVER "); } <br/>The draw (n, "lime"); <br/>If (n==food) while (snake. IndexOf (food=~ ~ (Math) random () * 400)) & gt; 0); The draw (food, "yellow"); } <br/>The else {the draw (snake. Pop (), "black"); } setTimeout (the arguments. The callee, 150); } (); <br/></script> <br/></body> </html> <br/><br/><br/>The above can <img SRC="https://img.codepudding.com/202010/149240180454221.gif" Alt=""/><p class="article - content rp"> CodePudding user response: </p><fieldset> <legend> reference 1/f, 75 flash ray's reply: <legend> <blockquote> & lt; ! DOCTYPE html> <html> <br/><head> <meta charset="utf-8"> <br/><title> Snake & lt;/title> <br/><style> <br/>{display: flex; justify-content: center; align-items: center; } <br/></style> <br/></head> <body> <br/><Canvas> Id="can" width="400" height="400" style="background - color: red" & gt; Does not support canver</canvas> <br/><The script type="text/javascript" & gt; <br/>Var snake=[200199] direction=1, the food=201, n. <br/>Var box=document. GetElementById () 'can'. GetContext (" 2 d "); The function the draw (seat, color) {<br/>Box. FillStyle=color; <br/>Box. FillRect (seat % 20 * 20 + 1, ~ ~ (20) seat/* 20 + 1,18,18); } the for (I=0; i<=399; I++) <br/>{the draw (I, "black"); } <br/>Document. The onkeydown=function (evt) {direction=snake [1] - snake [0]==(n=20,1,20] [- 1 - [(evt | | event). The keyCode to 37] | | direction)? Direction: n. }; <br/>! The function () {snake. Unshift (n=snake [0] + direction); If (snake. IndexOf (n, 1) & gt; 0 | | n<0 | | n> 399 | | direction==1 & amp; & N % 20==0 | | direction==1 & amp; & N % 20==19) <br/>{return alert (" GAME OVER "); } <br/>The draw (n, "lime"); <br/>If (n==food) while (snake. IndexOf (food=~ ~ (Math) random () * 400)) & gt; 0); The draw (food, "yellow"); } <br/>The else {the draw (snake. Pop (), "black"); } setTimeout (the arguments. The callee, 150); } (); <br/></script> <br/></body> </html> <br/><br/><br/>The above can <img SRC="https://img.codepudding.com/202010/149240180454221.gif" Alt=""/> </blockquote> <fieldset> <br/>What's the difference? Don't see ┐ ─ __ ─ ┌<p class="article - content rp"> CodePudding user response: </p><fieldset> <legend> reference 1/f, 75 flash ray's reply: <legend> <blockquote> & lt; ! DOCTYPE html> <html> <br/><head> <meta charset="utf-8"> <br/><title> Snake & lt;/title> <br/><style> <br/>{display: flex; justify-content: center; align-items: center; } <br/></style> <br/></head> <body> <br/><Canvas> Id="can" width="400" height="400" style="background - color: red" & gt; Does not support canver</canvas> <br/><The script type="text/javascript" & gt; <br/>Var snake=[200199] direction=1, the food=201, n. <br/>Var box=document. GetElementById () 'can'. GetContext (" 2 d "); The function the draw (seat, color) {<br/>Box. FillStyle=color; <br/>Box. FillRect (seat % 20 * 20 + 1, ~ ~ (20) seat/* 20 + 1,18,18); } the for (I=0; i<=399; nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull </div> <div class="th_page th_page_color"></div> <div class="umCopyright"> <p>Page link:<a href="/frontend/68081.html" target="_blank" style="color:#999">https//www.codepudding.com/frontend/68081.html</a></p> </div> <div class="detail-arr"> <div class="detail-arr-left">Prev:<a href='/frontend/68080.html'>There are big used badboy? Why do I always playback failure</a></div> <div class="detail-arr-right">Next:<a href='/frontend/68082.html'>Who to explain xslt3.0 Sweep</a></div> </div> </div> </div> </div> </div> <div class="container th_top"> <div class="row"> <div class="col-md-12"> <div class="hot-tags neitags"> <ul> <li><i class="iconfont icon-x-tags"></i> Tags:  </li> <a href='/e/tags/?tagname=JavaScript' target='_blank'>JavaScript</a> </ul> </div> </div> </div> </div> <div class="container th_top"> <div class="row"> <div class="col-md-12"> <div class="xiangguan"> <ul class="msg msghead"> <li class="tbname">Related</li> </ul> <ul> </ul> </div> </div> </div> </div> <div class="container th_top"> <div class="row"> <div class="col-md-12"> <div class="flinks"> <ul> <li><i class="iconfont icon-x-tags"></i> Links:  </li> <li class="liflinks"><a target="_blank" href="/" title="CodePudding">CodePudding</a></li> </ul> </div> </div> </div> </div> <div class="footer"> <p><span style="font-size:16px;color:#666;font-weight: bold">About Us:</span>  <a href="https://www.codepudding.com/contact.html">Contact Us</a>      <a href="https://www.codepudding.com/service.html">Terms of Service</a>      <a href="https://www.codepudding.com/privacy.html"> Privacy Policy</a></p> <p class="foot_info">Copyright © 2010-2023,Powered By <a href="/" target="_blank">CodePudding</a> </p> </div> <script type="text/javascript" src="/skin/code/tianhu.js"></script> </body></html>