Jump to content

TBreitenfeldt

New Members
  • Posts

    3
  • Joined

  • Last visited

TBreitenfeldt's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Thanks for the tip about the code tag, I have never posted code on a form before. Sorry, I should have been more specific. I am blind, I use a screen reader to use the computer. I say inaccessible because my screen reader doesn't function well with any of the web consuls that I mentioned earlier. So I am using that error script in an external Java Script, so all I have to do is enter in the script tag with the attribute src to use the file. It is only so effective though. If you have any suggestions for other ideas I could try with my screen reader for checking my code that would be very helpful. TJ Breitenfeldt
  2. Thanks for the help. I am actually visually impaired, so I have not cared to much about what the formatting of the code looks like. I went to the site you gave and managed to get all my Java Script spaced much better. I will try and start making it a habit to make my code look more like this. I still need some help. I have been trying to find a good way to check errors in my Java Script that is accessible, but I am having some problems. I have tried the web consul in Firefox, IE, and Google Chrome and none of them are accessible enough to for me to read the Java Script errors. I found some code for an error trapper for Java Script and that is what I have been using. Here is the code... function ErrorTrap(msg,url,lineNo) { window.alert("Error: " + msg + "\nLine: " + lineNo + "\nULR: " + url); } onerror = ErrorTrap; I have found a lot of errors with this, but I am stuck again. In Firefox I am getting an error: "Error: Script Error, Line 0" Internet Explorer: "Error: Syntax line: 117" which in notepad++ is my closing brase for my dice roll function. Chrome: "Error: Script Error, Line 0" I am not sure what to do. here is my html code again after the small change of moving the script tag to the bottom of the page. <!DOCTYPE HTML> <HTML LANG="EN"> <head> <title> Dice Game </title> <meta charset="utf-8"> <link href="format.css" rel="stylesheet" type="text/css" /> </head> <body> <div id="header"> <p class="page-title"> Dice Game </p> <p class="tagline"> Dueling Dice </p> </div> <div id="GameContent"> <h2> How to Score </h2> <p> You score by rolling a 6, which is worth 6 points, a double, which is worth 12 points, or a double 6 which is worth 18 points. </p> <h3> Dice Result </h3> <div id="diceRoll"> </div> <div id="score"> <h3> Score </h3> <p>player 1 score is:</p> <div id="player1Score"> </div> <p>Player2 score is:</p> <div id="player2Score"> </div> </div> <!-- end score --> <br> <br> <form> <input type="button" value="Roll" name="roll" id="roll" onclick="rollDice()" accesskey="r"> </form> </div> <!-- End content --> <script src="DiceRoll.js"> </script> </body> <code> </html> Here is my Java Script again, after I have made some changes... <code> var dice1; var dice2; var score = 0; var dice; var turn; var player1; var player2; function rollDice() { var dice1 = Math.floor(Math.random() * 6) + 1; var dice2 = Math.floor(Math.random() * 6) + 1; var diceRoll = document.getElementById("diceRoll") .innerHTML = dice1 + "<br/>" + dice2 + "<br/>"; //turns turn = player1 || player2; switch (turn) { case player1: if (document.getElementById("roll") .onclick == true) { turn = player2; } else { turn = player1; } break; case player2: if (document.getElementById("roll") .onclick == true) { turn = player1; } else { turn = player2; } break; default: turn = player1; } } var player1 = document.getElement.ById("player1Score") .innerHTML = player1; var player2 = document.getElementById("player2Score") .innerHTML = player2; turn = score; //rules for the game if (dice1 == 6 || dice2 == 6) { score += 6; } if (dice1 == dice2) { score += 12; } if (dice1 == 6 & dice2 == 6) { score += 6; } if (score > 99) { window.alert("you rolled a " + dice1 + " and " + dice2 + ". Your score is " + score + ". Congradulations you won!!!"); score = 0 } else { window.alert("you rolled a " + dice1 + " and " + dice2 + ". Your score is " + score + "."); } } If you have any ideas for possible ways I can try to error check my Java Script in a better way please let me know. Thanks, TJ Breitenfeldt
  3. I am sort of new to Java Script. I decided to practice my skills by creating a dice game using rules I made up based on the conditional statements in the logic. I was able to run the script fine as a very simple script where the dice would display on the page and based on the rules below, add up a score in a seperat spot on the page. However, I wanted to take it a step farther and add a "turn" bariable so that two people can play the game to win. I keep getting an error though saying that there is something wrong with my function. More spacifically... "Error Reference Error: rollDice is not defined Line 1" rollDice() is my function that I want to call onclick I am not sure what to do about this error. Can someone help! Here are the rules to the game I made. It is pretty obvius in the code where the conditional statements are for the rules. This game is played with two die. The goal is to roll a score greater than or equal to 100. You score by rolling a 6, which is worth 6 points, a double, which is worth 12 points, or a double 6 which is worth 18 points. Here is my HTML Code. <!DOCTYPE HTML> <HTML LANG="EN"> <head> <script src="DiceRoll.js"> </script> <title> Dice Game </title> <meta charset="utf-8"> <link href="format.css" rel="stylesheet" type="text/css" /> </head> <body> <div id="header"> <p class="page-title"> Dice Game </p> <p class="tagline"> Dueling Dice </p> </div> <div id="GameContent"> <h2> How to Score </h2> <p> You score by rolling a 6, which is worth 6 points, a double, which is worth 12 points, or a double 6 which is worth 18 points. </p> <h3> Dice Result </h3> <div id="diceRoll"> </div> <div id="score"> <h3> Score </h3> <p>player 1 score is:</p> <div id="player1Score"> </div> <p>Player2 score is:</p> <div id="player2Score"> </div> </div> <!-- end score --> <br> <br> <form> <input type="button" value="Roll" name="roll" id="roll" onclick="rollDice()" accesskey="r"> </form> </div> <!-- End content --> </body> </html> And here is my Java Script var dice1; var dice2; var score = 0; var dice; var turn; var player1; var player2; function rollDice() { var dice1=Math.floor(Math.random()*6)+1; var dice2=Math.floor(Math.random()*6)+1; var diceRoll =document.getElementById('diceRoll').innerHTML = dice1 + "<br/>" + dice2 + "<br/>"; //turns turn = player1 || player2; switch (turn) { case player1: if (document.getElementById("roll").onclick == true) { turn = player2; } else { turn = player1; } break; case player2: if (document.getElementById("roll").onclick == true) { turn = player1; } else { turn = player 2; } break; default: turn = player1; } } var player1=document.getElement.ById("player1Score").innerHTML = player1; var player2=document.getElementById("player2Score".innerHTML = player2;) turn = score; //Rules for the game if (dice1 == 6 || dice2 == 6) { score += 6; } if (dice1 == dice2) { score += 12; } if (dice1 ==6 & dice2 == 6) { score += 6; } if (score > 99) { alert("you rolled a " + dice1 + " and " + dice2 + ". Your score is " + score + ". Congradulations you won!!!"); score = 0 } else { alert("you rolled a " + dice1 + " and " + dice2 + ". Your score is " + score + "."); } } Right now I just want to get the script working, eventually I will make the html presentation look nicer. Hope someone can help, TJ Breitenfeldt
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.