This article describes the javascript-implemented number guessing game. Share it for your reference, as follows:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>js game</title><script type="text/JavaScript"> var x=10; //x=parseInt(Math.random()*(1000-1))+1; for(var i=0;i<10;i++){ var num=prompt("Please enter the number you guessed",""); if (num!=null && num!="") { if(num==x){ switch(i){ case 0: alert('It's so godly, guess right!'); i=10; break; case 1: alert('Awesome, yes!'); i=10; break; case 2: alert('Good, yes!'); i=10; break; case 3: alert('Okay, yes!'); i=10; break; case 3: alert('Okay, yes!'); i=10; break; case 4: alert('It's not easy, right!'); i=10; break; case 5: alert('It'll settle, right!'); i=10; break; case 6: alert('It's a bit slow, right!'); i=10; break; case 7: alert('Hurry up next time, right!'); i=10; break; case 8: alert('Catch it, right!'); i=10; break; case 9: alert('Last chance, right!'); i=10; break; } } if(i==9){ alert('Idiot, I guessed it 10 times!'); } if(num>x){ document.write("You have guessed it" + eval(i+1) + "times," + num +"," + "Big!<br>"); } if(num<x){ document.write("You have guessed" + eval(i+1) + "times," + num +"," + "Small!<br>"); } }else{ alert('can't be empty'); } }</script></head><body><div id="div1"></div></body></html>For more information about JavaScript related content, please check out the topics of this site: "Summary of JavaScript switching effects and techniques", "Summary of JavaScript search algorithm skills", "Summary of JavaScript animation effects and techniques", "Summary of JavaScript errors and debugging techniques", "Summary of JavaScript data structures and algorithm skills", "Summary of JavaScript traversal algorithms and techniques", and "Summary of JavaScript mathematical operations usage"
I hope this article will be helpful to everyone's JavaScript programming.