Advertisement
SmaJli

kocki ip kol2

Jun 13th, 2021
848
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 5 2.93 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4.     <meta charset="UTF-8">
  5.     <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6.     <title>Document</title>
  7.     <script src="https://code.jquery.com/jquery-3.5.1.min.js" integrity="sha256-9/aliU8dGd2tb6OSsuzixeV4y/faTqgFtohetphbbj0=" crossorigin="anonymous"></script>
  8. </head>
  9. <style>
  10.     .dice{
  11.         width: 150px;
  12.         height: 150px;
  13.         border: 2px solid black;
  14.         float: left;
  15.         font-size: 120px;
  16.         text-align: center;
  17.        
  18.     }
  19. </style>
  20. <body>
  21.  
  22.  
  23.     <input type="number" id="input" min="2" max="12">
  24.     <button id="roll" onclick="roll()">Roll</button>
  25.     <br><br>
  26.  
  27.     <div>
  28.         <div class="dice" id="dice1"></div>
  29.         <div class="dice" id="dice2"></div>
  30.     </div><br> <br> <br><br><br> <br><br><br> <br><br>
  31.  
  32.  
  33.     <div>
  34.         <button onclick="historyJson()">History to json</button>
  35.     </div>
  36.  
  37.     <script>
  38.             let data=[{"input":7,"dices":[1,6]},
  39.                      {"input":7,"dices":[6,2]},
  40.                      {"input":7,"dices":[1,5]},
  41.                      {"input":7,"dices":[1,4]}]
  42.  
  43.         let obj = JSON.parse(JSON.stringify(data))
  44.         console.log(obj)
  45.  
  46.         let history = []
  47.  
  48.  
  49.         function roll(){
  50.             let inputVal = $("#input").val()
  51.             if(!inputVal){
  52.                 alert("vnesi brojka")
  53.                 return ;
  54.             }
  55.  
  56.             let time = setInterval(function(){
  57.                 generate();
  58.             }, 50)
  59.             let time2 = setInterval(function(){
  60.                 generate2();
  61.             }, 80)
  62.  
  63.             setTimeout(function(){
  64.                 clearInterval(time)
  65.                 clearInterval(time2)
  66.             },2000)
  67.  
  68.             setTimeout( function(){
  69.                 let kocka1 = parseInt($("#dice1").html())
  70.                 let kocka2 = parseInt($("#dice2").html())
  71.                 console.log($("#dice1").html())
  72.                 console.log($("#dice2").html())
  73.                 console.log(kocka1+kocka2)
  74.                 console.log(inputVal, typeof inputVal)
  75.                 if(kocka1+kocka2 === parseInt(inputVal)){
  76.                     $("#input").css("background", "green")
  77.                 }else{
  78.                     $("#input").css("background", "red")
  79.                 }
  80.                 history.push({
  81.                     input: inputVal,
  82.                     dices : [kocka1, kocka2]
  83.                 })
  84.             },2200)
  85.  
  86.  
  87.  
  88.         }
  89.  
  90.         function historyJson(){
  91.             alert(JSON.stringify(history))
  92.         }
  93.  
  94.         function generate(){
  95.             let a = random();
  96.            
  97.  
  98.             $("#dice1").html(a)
  99.            
  100.         }
  101.  
  102.         function generate2(){
  103.             let b = random();
  104.             $("#dice2").html(b)
  105.  
  106.         }
  107.  
  108.  
  109.         function random(){
  110.             return (Math.floor(Math.random()*6)+1)  
  111.         }
  112.  
  113.        
  114.     </script>
  115.  
  116. </body>
  117. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement