Advertisement
MEI-BoatRider

1 0 game

Feb 26th, 2020
277
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //variables
  2.      var wallet = 0;
  3.      var a = 0;
  4.      var roundlength = prompt ('length of the game?');
  5.      if (roundlength == '')
  6.      {roundlength = 5;}
  7. //prompt   (how long does the game go?);
  8.      
  9.  do  {var playerinput = prompt('1 or 0, your guess!');
  10. // prompt    (1 or 0? (avoid other characters!));
  11.  
  12. //introduces the game
  13. console.log('1', '0', 'game!', '');
  14.  
  15. //asks if youd like an explanation
  16. var question = prompt
  17. ("would you like an explanation?  1/0?")
  18. switch(question){
  19.        //y or n switch statement
  20.     case '1':
  21.    
  22.     console.log
  23.     ("the goal of the game is to get more points by luck, guess one or zero, if the computer generates a one and you choose one, you get a point! otherwise if it doesnt match then you lose a point!", "");
  24.  
  25.         break;
  26.    
  27.     case '0':  
  28.    
  29.         break;
  30.        
  31.     case '':
  32.     break;
  33.    
  34.         default:
  35.     console.log
  36.     ("that is not a valid input");
  37. }
  38.  
  39. //math for 0 or 1.
  40. for (var x = 0; x < roundlength; x++) {
  41.     var numberRand = Math.random();
  42.         if (numberRand < 0.5)  
  43.          {numberRand = 0} //for 0
  44. else {numberRand = 1}; //for 1
  45.      console.log('[RNG]' +numberRand);
  46.         //prints it
  47.         switch(numberRand) {
  48.             case 1:
  49.              
  50.              switch(playerinput) {
  51.                 case '1':
  52.                 ++wallet;
  53.                 console.log('[W]' + wallet);
  54.                 break;
  55.                
  56.                 case '0':
  57.                 --wallet;
  58.                 console.log('[w]' + wallet);
  59.                 break;}
  60.             break;
  61.            
  62.             case 0:
  63.            
  64.             switch(playerinput) {
  65.                 case '1':
  66.                 --wallet;
  67.                 console.log('[w]' + wallet);
  68.                 break;
  69.                
  70.                 case '0':
  71.                 ++wallet;
  72.                 console.log('[w]' + wallet);
  73.                 break;
  74.             }
  75.             break;
  76.     }
  77.  }
  78. }
  79. while (a > 0);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement