Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Meh-tzee

ID: 3793330 • Letter: M

Question

HTML/JAVA Script

I have a simple yahtzee game im trying to make, thats a bit different than regular: The problem i'm having is I need to be able to hold values when I click on them, as well as doing the math when I click on a certain number after the code is running. There is comments of where code has been redacted and information of where things need to go.

Here is my code so far (note everything works at the moment and there is comments where things should be):

The information for the website images is user: cs316 pass: pizzapie

Explanation / Answer

Meh-tzee table#Dice { width: 60%; border: 3px solid black; } table#Dice th, td { border: 3px solid black; } table#ScoreCard { width: 60%; border: 1px solid black; } table#ScoreCard th { text-align: center; border: 1px solid black; } table#ScoreCard tr td { width: 43%; text-align: center; border: 1px solid black; } table#ScoreCard tr td:nth-child(1) { width: 14%; border: 3px solid black; } table#Dice td { image-align: center; } table#WinLoss td { text-align: center; } #Roll, #NewGame { width: 60%; text-align: center; font-size: 1.5em; } h1 { font-size: 2em; width: 60%; text-align: center; } var defaultPath = "http://www.cs.uky.edu/~paul/CS316/P2/"; var totalGames = 0; var cWins = 0; // computer win total var pWins = 0; // player win total var diceValues = [0, 0, 0, 0, 0, 0]; // values of dice var heldValues = [false, false, false, false, false, false]; // is a die held? // the different scoring slots // 1s 2s 3s 4s 5s 6s bonus mehtzee total var compScore = [0, 0, 0, 0, 0, 0, 0, 0, 0]; var playerScore = [0, 0, 0, 0, 0, 0, 0, 0, 0]; var currentTurn = 0; // current turn, duh! var maxTurns = 7; var currentRoll = 0; var MAXROLLS = 4; function load() { newgame = document.getElementById("NewGame"); newgame.addEventListener("click", ModNewGame); } // Make NewGame clickable..... function ModNewGame(theEvent) { newgame = document.getElementById("NewGame"); newgame.onclick = StartGame(newgame); } function StartGame(newgame) { newgame.innerHTML = "Game Started!"; ResetScores(); updateWins(); resetDice(); ResetButtons(); currentTurn = 0; } function ResetScores() { var slot = ""; var maxSlots = playerScore.length; for(i = 0 ; i < (playerScore.length-1) ; i++) { playerScore[i] = 0; compScore[i] = 0; } } function resetDice() { // console.log("Inside resetDice()!"); for (i = 0 ; i = compScore[playerScore.length-1]) { newMessage("You won!") pWins += 1; } else { newMessage("You lost!") cWins += 1; } } function updateTotal(isPlayer) { var total = 0; var scoresSize = playerScore.length - 1; // redacted } function computeScore(player, slot, element) { var singlesTotal = 0; var dieValue = parseInt(slot)+1; // console.log("computeScore = "+slot); if (slot < 6) { // add like dice // redacted } if (slot == 7) { // mehtzee slot // redacted } return singlesTotal; } function toggleHold() { console.log("In toggleHold!"); console.log("In toggleHold, src="+this.src); console.log("In toggleHold, src = "+this.id); var toggle = doToggle(this.id, this.src); this.src = toggle; }