Advertisement
Guest User

Untitled

a guest
Sep 24th, 2019
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.19 KB | None | 0 0
  1. <html>
  2.  
  3. <head>
  4. <meta charset="UTF-8"/>
  5.  
  6.  
  7. </head>
  8.  
  9.  
  10.  
  11. </style>
  12. <script>
  13.  
  14. function start(){
  15. z = 0;
  16. z = Math.round((Math.random() * 99)+1);
  17. zycia=8;
  18. proba=0;
  19. document.getElementById('life').innerHTML = 'Ilość żyć ' + zycia;
  20. document.getElementById('proby').innerHTML = 'Ilość ruchów ' + proba;
  21. alert('Zaczynamy');
  22. document.getElementById('podana').focus();
  23. }
  24.  
  25. function sprawdz(){
  26. if (czyliczba())
  27. {
  28. if(document.getElementById('podana').value == z)
  29. {
  30. alert('wygrałeś');
  31. if (confirm('Jeszcze raz?'))
  32. {
  33. start();
  34. document.getElementById('podana').value = ' ';
  35. }
  36. else
  37. location.reload();
  38. }
  39. else if(document.getElementById('podana').value > z)
  40. {
  41. alert('podaj mniejszą');
  42. zycia = zycia - 1;
  43. proba = proba + 1;
  44. document.getElementById('life').innerHTML = 'Ilość żyć ' + zycia;
  45. if(zycia == 0)
  46. {
  47. alert('Przegrałeś');
  48. if (confirm('Jeszcze raz?'))
  49. {
  50. start();
  51. document.getElementById('podana').value = ' ';
  52. }
  53. else
  54. location.reload();
  55. }
  56. document.getElementById('proby').innerHTML = 'Ilość ruchów ' + proba;
  57. document.getElementById('podana').value = ' ';
  58. document.getElementById('podana').focus();
  59. }
  60. else if(document.getElementById('podana').value < z)
  61. {
  62. alert('podaj większą');
  63. zycia = zycia - 1;
  64. proba = proba + 1;
  65. document.getElementById('life').innerHTML = 'Ilość żyć ' + zycia;
  66. if(zycia == 0)
  67. {
  68. alert('Przegrałeś');
  69. if (confirm('Jeszcze raz?'))
  70. {
  71. start();
  72. document.getElementById('podana').value = ' ';
  73. }
  74. else
  75. location.reload();
  76. }
  77. document.getElementById('proby').innerHTML = 'Ilość ruchów ' + proba;
  78. document.getElementById('podana').value = ' ';
  79. document.getElementById('podana').focus();
  80. }
  81. }
  82. else if(!czyliczba())
  83. {
  84. alert('Podaj liczbę z zakresu <1;100>');
  85. document.getElementById('podana').value = ' ';
  86. document.getElementById('podana').focus();
  87. }
  88. }
  89.  
  90. function czyliczba(){
  91. if ((document.getElementById('podana').value >= 1) && (document.getElementById('podana').value <= 100))
  92. return true;
  93. return false;
  94. }
  95. var start;
  96. function time(){
  97. var wyniki = [];
  98. var start = Date.now();
  99. imie = prompt ('Dawaj imie')
  100. //alert('Wystartowalismy to zastopuj');
  101. //var stop = Date.now();
  102.  
  103. }
  104. function stoptime(){
  105.  
  106. var stop = Date.now();
  107. czas_ms = (stop - start)/1000;
  108. alert('Uplynelo' + czas_ms + ' sekundy');
  109.  
  110. wyniki.push({imie, czas_ms});
  111.  
  112. koniec_zabawy = prompt('Konczymy? t=tak, nie to wpisz cokolwiek');
  113.  
  114. if(koniec_zabawy == 't') {break};
  115.  
  116.  
  117. }
  118.  
  119. </script>
  120. <body>
  121.  
  122. <div class="box1">
  123. <p id="gratytul">Zgadnij liczbe</p><hr>
  124. <div id="gra">
  125. <div id="grasrodek">
  126. <input type="text" name="podana" id="podana" ><br>
  127. <input type="button" name="START" value="START" onclick="start()">
  128. <input type="button" name="Time" value="time" onclick="time()" >
  129. <input type="button" name="Sprawdz" value="Sprawdz" onclick="sprawdz()" ><br />
  130. </div>
  131. <p id="life"></p>
  132. <p id="proby"></p>
  133. </div>
  134. </div>
  135.  
  136. </body>
  137.  
  138.  
  139.  
  140.  
  141. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement