Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Document</title>
- <script src="https://code.jquery.com/jquery-3.5.1.min.js" integrity="sha256-9/aliU8dGd2tb6OSsuzixeV4y/faTqgFtohetphbbj0=" crossorigin="anonymous"></script>
- </head>
- <style>
- .dice{
- width: 150px;
- height: 150px;
- border: 2px solid black;
- float: left;
- font-size: 120px;
- text-align: center;
- }
- </style>
- <body>
- <input type="number" id="input" min="2" max="12">
- <button id="roll" onclick="roll()">Roll</button>
- <br><br>
- <div>
- <div class="dice" id="dice1"></div>
- <div class="dice" id="dice2"></div>
- </div><br> <br> <br><br><br> <br><br><br> <br><br>
- <div>
- <button onclick="historyJson()">History to json</button>
- </div>
- <script>
- let data=[{"input":7,"dices":[1,6]},
- {"input":7,"dices":[6,2]},
- {"input":7,"dices":[1,5]},
- {"input":7,"dices":[1,4]}]
- let obj = JSON.parse(JSON.stringify(data))
- console.log(obj)
- let history = []
- function roll(){
- let inputVal = $("#input").val()
- if(!inputVal){
- alert("vnesi brojka")
- return ;
- }
- let time = setInterval(function(){
- generate();
- }, 50)
- let time2 = setInterval(function(){
- generate2();
- }, 80)
- setTimeout(function(){
- clearInterval(time)
- clearInterval(time2)
- },2000)
- setTimeout( function(){
- let kocka1 = parseInt($("#dice1").html())
- let kocka2 = parseInt($("#dice2").html())
- console.log($("#dice1").html())
- console.log($("#dice2").html())
- console.log(kocka1+kocka2)
- console.log(inputVal, typeof inputVal)
- if(kocka1+kocka2 === parseInt(inputVal)){
- $("#input").css("background", "green")
- }else{
- $("#input").css("background", "red")
- }
- history.push({
- input: inputVal,
- dices : [kocka1, kocka2]
- })
- },2200)
- }
- function historyJson(){
- alert(JSON.stringify(history))
- }
- function generate(){
- let a = random();
- $("#dice1").html(a)
- }
- function generate2(){
- let b = random();
- $("#dice2").html(b)
- }
- function random(){
- return (Math.floor(Math.random()*6)+1)
- }
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement