Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <html>
- <body>
- <div id="button_list">
- </div>
- <br />
- <div id="total_bet">
- </div>
- <br />
- <div id="chip_list">
- </div>
- <script type="text/javascript">
- var chip_types = [1000, 5000, 10000, 25000, 50000, 100000];
- var total_bet = 0;
- build();
- function build() {
- var button_list = document.getElementById("button_list");
- chip_types.forEach(function(chip_type) {
- var node = document.createElement("button");
- var textnode = document.createTextNode(chip_type);
- node.appendChild(textnode);
- node.onclick = function() {
- addBet(chip_type);
- };
- button_list.appendChild(node);
- });
- }
- function addBet(bet) {
- total_bet += bet;
- var text_total_bet = document.getElementById("total_bet");
- text_total_bet.innerHTML = "Total bet : " + total_bet;
- showChips();
- };
- function showChips() {
- var chip_list = document.getElementById("chip_list");
- var chips = calculateChips();
- var text_chip_list = "Chips : <br/>";
- for (var i = 0; i < chips.length; i++) {
- for (var j = 0; j < chips[i]; j++) {
- text_chip_list += chip_types[i] + "<br/>";
- };
- };
- chip_list.innerHTML = text_chip_list;
- };
- function calculateChips() {
- var result = [];
- var temp_total_bet = total_bet;
- for (var i = chip_types.length - 1; i >= 0; i--) {
- var total_chip = Math.floor(temp_total_bet / chip_types[i]);
- result.unshift(total_chip);
- temp_total_bet -= total_chip * chip_types[i];
- };
- return result;
- }
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement