Advertisement
mahlichavpm

Task1

Aug 1st, 2022
751
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function getThrow(){
  2.     let arr = [];
  3.     for(let i = 0; i < 3; i++){
  4.         arr.push(Math.floor((Math.random()*6) +1 ));
  5.     }
  6.     return arr;
  7. }
  8.  
  9. let counter = 0;
  10. let pairCount = 0;
  11.  
  12. while(true){
  13.     let dice = getThrow();
  14.     let validNumbers = true;
  15.  
  16.     for(let i = 0; i < dice.length; i++){
  17.         if(dice[i] < 1 || dice[i] > 6){
  18.             validNumbers = false;
  19.             break;
  20.         }
  21.     }
  22.     counter++;
  23.  
  24.     if(!validNumbers){
  25.         pairCount = 0;
  26.         continue;
  27.     }
  28.  
  29.     if(dice[0] == 6 && dice[1] == 6 && dice[2] == 6){
  30.         pairCount++;
  31.     } else {
  32.         pairCount = 0;
  33.     }
  34.  
  35.     if(pairCount == 6){
  36.         break;
  37.     }
  38. }
  39.  
  40. console.log(`Otne ${counter} opita da hvurlq 6 poredni zara s maksimalen broi!`);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement