Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //variables
- var wallet = 0;
- var a = 0;
- var roundlength = prompt ('length of the game?');
- if (roundlength == '')
- {roundlength = 5;}
- //prompt (how long does the game go?);
- do {var playerinput = prompt('1 or 0, your guess!');
- // prompt (1 or 0? (avoid other characters!));
- //introduces the game
- console.log('1', '0', 'game!', '');
- //asks if youd like an explanation
- var question = prompt
- ("would you like an explanation? 1/0?")
- switch(question){
- //y or n switch statement
- case '1':
- console.log
- ("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!", "");
- break;
- case '0':
- break;
- case '':
- break;
- default:
- console.log
- ("that is not a valid input");
- }
- //math for 0 or 1.
- for (var x = 0; x < roundlength; x++) {
- var numberRand = Math.random();
- if (numberRand < 0.5)
- {numberRand = 0} //for 0
- else {numberRand = 1}; //for 1
- console.log('[RNG]' +numberRand);
- //prints it
- switch(numberRand) {
- case 1:
- switch(playerinput) {
- case '1':
- ++wallet;
- console.log('[W]' + wallet);
- break;
- case '0':
- --wallet;
- console.log('[w]' + wallet);
- break;}
- break;
- case 0:
- switch(playerinput) {
- case '1':
- --wallet;
- console.log('[w]' + wallet);
- break;
- case '0':
- ++wallet;
- console.log('[w]' + wallet);
- break;
- }
- break;
- }
- }
- }
- while (a > 0);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement