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