Posted By

Waldio on 03/31/11


Tagged

scripts


Versions (?)

Hoger/lager game


 / Published in: JavaScript
 

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  2. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="nl" lang="nl">
  4. <head>
  5. <script type="text/javascript">
  6. function rand (n){
  7. return ( Math.floor(Math.random() * n + 1 ));
  8. }
  9.  
  10. var raad = rand(10);
  11.  
  12. function displayMessage(form){
  13. var input = form.MyInput.value;
  14.  
  15. document.Game.Controle.value = raad;
  16.  
  17. if(input < raad){
  18. document.Game.Answer.value = "Hoger";
  19. }
  20.  
  21. if(input > raad){
  22. document.Game.Answer.value = "Lager";
  23. }
  24.  
  25. if(input == raad){
  26. document.Game.Answer.value = "Correct";
  27. raad = rand(10);
  28. }
  29. }
  30. </script>
  31. </head>
  32. <body>
  33. <form name="Game">
  34. Raad het getal tussen 1 en 10<br/>
  35. <input name="MyInput" type="text" value=""/>
  36. <input type="button" value="Click me!" onclick="displaymessage(this.form)" />
  37. <br/><br/>
  38. <input name="Answer" type="text"/>
  39. </form>
  40. </body>
  41. </html>

Report this snippet  

You need to login to post a comment.