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U,UAAUC,IAAI,UACrBnB,SACGC,cAAc,YAAYa,gBAC1BI,UAAUC,IAAI,kBACjBnB,SACGC,cAAc,YAAYa,gBAC1BI,UAAUE,OAAO,mBAGpBC,mBAONZ,OAAOc,iBAAiB,QAASP","sources":["script.js"],"sourcesContent":["'use strict';\n\n// Selecting Elements\nconst player0El = document.querySelector('.player--0');\nconst player1El = document.querySelector('.player--1');\nconst score0El = document.querySelector('#score--0');\nconst score1El = document.getElementById('score--1');\nconst current0El = document.getElementById('current--0');\nconst current1El = document.getElementById('current--1');\nconst diceEl = document.querySelector('.dice');\nconst btnNew = document.querySelector('.btn--new');\nconst btnRoll = document.querySelector('.btn--roll');\nconst btnHold = document.querySelector('.btn--hold');\n\nlet scores, currentScore, activePlayer, playing;\n\n// Starting Conditions\nconst init = function () {\n scores = [0, 0];\n currentScore = 0;\n activePlayer = 0;\n playing = true;\n\n score0El.textContent = 0;\n score1El.textContent = 0;\n current0El.textContent = 0;\n current1El.textContent = 0;\n\n diceEl.classList.add('hidden');\n player0El.classList.remove('player--winner');\n player1El.classList.remove('player--winner');\n player0El.classList.add('player--active');\n player1El.classList.remove('player--active');\n};\n\ninit();\n\nconst switchPlayer = function () {\n document.getElementById(`current--${activePlayer}`).textContent = 0;\n activePlayer = activePlayer === 0 ? 1 : 0;\n currentScore = 0;\n player0El.classList.toggle('player--active');\n player1El.classList.toggle('player--active');\n};\n\n// Rolling Dice Functionality\nbtnRoll.addEventListener('click', function () {\n if (playing) {\n // 1. Generating a random dice roll\n const dice = Math.trunc(Math.random() * 6) + 1;\n // 2. Display dice\n diceEl.classList.remove('hidden');\n diceEl.src = `dice-${dice}.png`;\n\n // 3. Check for rolled 1: if true, switch player\n if (dice !== 1) {\n // Add dice to current score\n currentScore += dice;\n document.getElementById(`current--${activePlayer}`).textContent =\n currentScore;\n } else {\n // Switch player\n switchPlayer();\n }\n }\n});\n\nbtnHold.addEventListener('click', function () {\n if (playing) {\n // 1. Add current score to active player's score\n scores[activePlayer] += currentScore;\n document.getElementById(`score--${activePlayer}`).textContent =\n scores[activePlayer];\n // 2. Check if the player's score is >= 100\n if (scores[activePlayer] >= 100) {\n // Finish game\n playing = false;\n diceEl.classList.add('hidden');\n document\n .querySelector(`.player--${activePlayer}`)\n .classList.add('player--winner');\n document\n .querySelector(`.player--${activePlayer}`)\n .classList.remove('player--active');\n } else {\n // Switch to next player\n switchPlayer();\n }\n }\n});\n\n// Resetting the game\n\nbtnNew.addEventListener('click', init);\n"],"names":["player0El","document","querySelector","player1El","score0El","score1El","getElementById","current0El","current1El","diceEl","btnNew","btnRoll","btnHold","scores","currentScore","activePlayer","playing","init","textContent","classList","add","remove","switchPlayer","toggle","addEventListener","dice","Math","trunc","random","src"],"version":3,"file":"index.1f02a55d.js.map"}