SHARE
TWEET

Angka Misterius

gunawantw Jul 26th, 2019 (edited) 53 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <html>
  2. <head>
  3. <title>Menebak angka misterius</title>
  4. </head>
  5. <body>
  6.     <form>
  7.         Tebak angka misterius 1-50 di sini <br>
  8.         <input type="text" name="tebak" size="10">
  9.         <br><input id="submitTebakan" type="button" onclick="doGuess()" value="TEBAK">
  10.         <input id="main-lagi" type="button" onClick="javascript:location.reload()" value="Main Lagi dong" style="display:none">
  11.  
  12.         <div id="pesan1"></div>
  13.         <br><br><div id="pesan2"></div>
  14.         <br><br><div id="history_tebakan"></div>
  15.         <br><br>
  16.        
  17.        
  18.     </form>
  19. </body>
  20. <script>
  21.     /*
  22.         Menebak angka misterius dari angka 1 sampai dengan 50
  23.         code dibuat oleh Gunawan T Wicaksono
  24.     */
  25.  
  26.     tebak = 0
  27.     bilanganAcak = Math.floor(Math.random() * 50)
  28.  
  29.     f = document.forms[0]
  30.  
  31.     function doGuess() {
  32.         myNumber = f.tebak.value
  33.         //alert(bilanganAcak)
  34.         if (myNumber == bilanganAcak) {
  35.             tulisPesan1('HORE, kamu berhasil menabak angka misterius, yaitu angka ' + bilanganAcak + ".")
  36.             berhenti()            
  37.         } else {
  38.  
  39.             if (myNumber > bilanganAcak ) {
  40.                 tulisPesan1('tebakan Anda lebih besar! ' )
  41.             } else {
  42.                 tulisPesan1('tebakan Anda lebih kecil! ' )
  43.             }
  44.         }
  45.         simpan(myNumber);
  46.         catatLog()
  47.     }
  48.  
  49.     function tulisPesan1(isiPesan) {
  50.         document.getElementById('pesan1').innerHTML = isiPesan
  51.     }
  52.  
  53.     function tulisPesan2(isiPesan) {
  54.         document.getElementById('pesan2').innerHTML = isiPesan
  55.     }
  56.  
  57.     function catatLog() {
  58.         tebak++
  59.         tulisPesan2("kamu telah menebak sebanyak "+tebak + " kali.")
  60.     }
  61.  
  62.     function simpan(x) {
  63.         document.getElementById('history_tebakan').innerHTML = document.getElementById('history_tebakan').innerHTML + ' ' + x
  64.     }
  65.  
  66.     function berhenti() {
  67.         document.getElementById('submitTebakan').disabled = true
  68.         document.getElementById('main-lagi').style.display = '';
  69.  
  70.     }
  71.  
  72.     function stopRKey(evt) {
  73.         var evt = (evt) ? evt : ((event) ? event : null);
  74.         var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);
  75.         if ((evt.keyCode == 13) && (node.type=="text"))  {return false;}
  76.     }
  77.  
  78. document.onkeypress = stopRKey;
  79. </script>
  80. </html>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top