jQuery addClass example

Change class name on click in jQuery

by skwjdgn

HTML

<script src='//rawgit.com/eu81273/jsfiddle-console/master/console.js'></script>

JavaScript

//m 이상 n 이하의 무작위 정수를 반환합니다.
function rand(m ,n){
	return m + Math.floor((n - m + 1) * Math.random());
}

//크라운 앤 앵커 게임의 여섯 그림 중 하나에 해당하는 문자열을 무작위로 반환합니다.
function randFace(){
	return ["crown", "anchor", "heart", "spade", "club", "diamond"]
  	[rand(0, 5)];
}

let crown_anchor = {
		doBet : function(){
     //돈을 겁니다.
        return rand(1, funds);
    },
    remainingBet : function(totalBet){
      if(totalBet === 7){
        totalBet = funds;
        bets.heart = totalBet;
      }else{
        //판돈을 나눕니다.
        let remaining = totalBet;

        do{
          let bet = rand(1, remaining);
          let face = randFace();
          bets[face] = bets[face] + bet;
          remaining = remaining - bet;
        }while(remaining > 0)
       }
     funds = funds - totalBet;
     console.log("\t bets: " + Object.keys(bets).map(face => `${face}: ${bets[face]} pence`).join(', ')  + 			` (total: ${totalBet} pence)`);
  

    },
    rollDice : function(){
      //주사위를 굴립니다.
      const hand = [];
      for(let roll = 0; roll < 3; roll++){
         hand.push(randFace());
      }
      console.log(`\t hand: ${hand.join(', ')}`);
      return hand;

    },
    makeMoney : function(hand){
      //딴 돈을 가져옵니다.
      let winnings = 0;
      for(let die = 0; die < hand.length; die++){
        let face = hand[die];
        if(bets[face] > 0) winnings = winnings + bets[face];
      }
      funds = funds + winnings;
      console.log(`\t winnings: ${winnings}`);
   	
   }
    
   
    
}

function doGame(funds){
	const game = crown_anchor;
  let round = 0;
	
	while(funds > 0 && funds < 100){
      round++;
      console.log(`rond ${round}:`);
      console.log(`\t starting funds : ${funds}p`);
      
      let totalBet = game.doBet();
			game.remainingBet(totalBet);
      const hand = game.rollDice();
      game.makeMoney(hand);
			
    console.log("=====================================");
  }

  console.log(`\t ending funds: ${funds}`);

}

let bets = { crown : 0, anchor: 0, heart:...