seulki
12-11-2010, 07:52 AM
>w< ello ello...I do not know what I'm doing wrong... >.< any help possible i'd feel really grateful :3. I'm in an intro to computer programming class XD so i do not know much for coding in javascript.
The player’s initial roll is known as his point. The point can be an immediate winner (7 or 11) or an immediate loser (2 or 3). If the player’s point does not equal one of these game-ending totals, then the player must continue rolling until he either rolls his point again (a winner) or obtains a 7 (a loser).
For example, the following sequence of rolls would cause the player to win:
Initial roll: 6 (player’s point)
Next roll: 10
Next roll: 4
Next roll: 11
Next roll: 6
WINNER!
When the user clicks a button, this event should call a function that rolls the dice until the player wins or loses. When implementing this function, use the below pseudocode as a guide. The value of each roll should be displayed in a text area, along with a message indicating whether the player won or lost (like in the example above).
this is what i have so far :O~
<html>
<!-- craps.html Dave Reed -->
<!-- This page stimulates a game of craps. -->
<!-- ===================================== -->
<head>
<title> A Game of Craps </title>
<script type="text/javascript">
function Craps()
//Assumes: Text area is avaliable for displaying results
//Results: displays the value of each roll, display a message whether the play won or lost
{
var roll1, roll2, nextRoll, myPoint;
roll1 = RandomInt(1, 6);
roll2 = RandomInt(1, 6);
myPoint = roll1 + roll2;
myPoint = parseFloat(myPoint);
document.getElementById("outputArea").value = "Initial Roll: " + myPoint + "\n";
if (myPoint == 7 || myPoint == 11) {
document.getElementById("outputArea").value = document.getElementById("outputArea").value + "WINNER!" + "\n";
}
else if (myPoint == 2 || myPoint == 3) {
document.getElementById("outputArea").value = document.getElementById("outputArea").value + "Loser!" + "\n";
}
else {
while (myPoint != 7 || myPoint != nextRoll) {
roll1 = RandomInt(1, 6);
roll2 = RandomInt(1, 6);
myPoint = roll1 + roll2;
nextRoll = parseFloat(myPoint);
document.getElementById("outputArea").value = document.getElementById("outputArea").value + "Next Roll " + myPoint + "\n";
}
if (myPoint == nextRoll) {
document.getElementById("outputArea").value = document.getElementById("outputArea").value + "WINNER!" + "\n";
}
if (nextRoll == 7){
document.getElementById("outputArea").value = document.getElementById("outputArea").value + "LOSER!" + "\n";
}
}
}
</script>
</head>
<body>
<div style="text-align:center">
<h2> A Game of Craps </h2>
<p>
<input type="button" value="Press to play a game of Craps" onclick="Craps();" />
</p>
<p>
<textarea id="outputArea" rows="15" cols="20"> </textarea>
</p>
</div>
</body>
</html>
Thank you :3
The player’s initial roll is known as his point. The point can be an immediate winner (7 or 11) or an immediate loser (2 or 3). If the player’s point does not equal one of these game-ending totals, then the player must continue rolling until he either rolls his point again (a winner) or obtains a 7 (a loser).
For example, the following sequence of rolls would cause the player to win:
Initial roll: 6 (player’s point)
Next roll: 10
Next roll: 4
Next roll: 11
Next roll: 6
WINNER!
When the user clicks a button, this event should call a function that rolls the dice until the player wins or loses. When implementing this function, use the below pseudocode as a guide. The value of each roll should be displayed in a text area, along with a message indicating whether the player won or lost (like in the example above).
this is what i have so far :O~
<html>
<!-- craps.html Dave Reed -->
<!-- This page stimulates a game of craps. -->
<!-- ===================================== -->
<head>
<title> A Game of Craps </title>
<script type="text/javascript">
function Craps()
//Assumes: Text area is avaliable for displaying results
//Results: displays the value of each roll, display a message whether the play won or lost
{
var roll1, roll2, nextRoll, myPoint;
roll1 = RandomInt(1, 6);
roll2 = RandomInt(1, 6);
myPoint = roll1 + roll2;
myPoint = parseFloat(myPoint);
document.getElementById("outputArea").value = "Initial Roll: " + myPoint + "\n";
if (myPoint == 7 || myPoint == 11) {
document.getElementById("outputArea").value = document.getElementById("outputArea").value + "WINNER!" + "\n";
}
else if (myPoint == 2 || myPoint == 3) {
document.getElementById("outputArea").value = document.getElementById("outputArea").value + "Loser!" + "\n";
}
else {
while (myPoint != 7 || myPoint != nextRoll) {
roll1 = RandomInt(1, 6);
roll2 = RandomInt(1, 6);
myPoint = roll1 + roll2;
nextRoll = parseFloat(myPoint);
document.getElementById("outputArea").value = document.getElementById("outputArea").value + "Next Roll " + myPoint + "\n";
}
if (myPoint == nextRoll) {
document.getElementById("outputArea").value = document.getElementById("outputArea").value + "WINNER!" + "\n";
}
if (nextRoll == 7){
document.getElementById("outputArea").value = document.getElementById("outputArea").value + "LOSER!" + "\n";
}
}
}
</script>
</head>
<body>
<div style="text-align:center">
<h2> A Game of Craps </h2>
<p>
<input type="button" value="Press to play a game of Craps" onclick="Craps();" />
</p>
<p>
<textarea id="outputArea" rows="15" cols="20"> </textarea>
</p>
</div>
</body>
</html>
Thank you :3