Java HALP

Started by Adonis, December 16, 2009, 09:10:07 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Adonis

Okay, this is what I have insofar. I need to figure out how to set a base "pot" value of 50, and make it keep a running total of the bet amounts as they are won and lost.
Quote<html>
<head>
<title>Brian's Crappy Java </title>


<script type="text/javascript">

function rolldice() {
var die1 = 1   Math.floor(Math.random() * 6);
var die2 = 1   Math.floor(Math.random() * 6);
sum = die1   die2;
point = sum;
}

function rollagain() {
var die1 = 1   Math.floor(Math.random() * 6);
var die2 = 1   Math.floor(Math.random() * 6);
sum = die1   die2;
}

function process1() {
var die1, die2, sum, point;

if (point == 0) {
rolldice();
}
else if (sum == 11 || sum == 7) {
   window.alert("Natural! You win!");
}
else if (sum == 12 || sum == 3 || sum == 2) {
   window.alert("Craps! You lose!");
}
else if (sum == 10 || sum == 9 ||sum == 8 ||sum == 6 ||sum == 5 ||sum == 4) {
   window.alert("Roll again to match your point");
}
}
function process2() {
var die1, die2, sum;

if (sum == 7) {
   window.alert("Seven-Out! You lose!")
}
else if (sum = point) {
   window.alert("You Win!")
}
else {
("Please roll again")
}
}
</script>
</head>


<body>
<script type="text/javascript">
var bet = prompt(" You have 50$ to start with. Please enter the amount you wish to bet here")
bet = parseInt(bet)
while (bet <= 0) {
   bet = prompt("That's not enough money! Please enter a larger bet!")
   bet = parseInt(bet)
}
while (bet > 50) {
   bet = prompt("You only have 50$! That is too much! Please enter another amount!")
   bet = parseInt(bet)
}   


</script>

</body>
</html>
You can't change who people are at their core. You can only love them for what they've given you.
O/O's
Current Muse Status: Overdriiiive

Vekseid

1) It's javascript. Java is a completely separate language.
2) Your functions are more complex than they need to be
3) Store referenced data (you can do this by declaring a variable or class containing it globally, otherwise you can also put it on the page for reference via document.getElementById('name').InnerHTML... that's how the ons and offs system works here : )
4) Use the code tags

<script type="text/javascript">
var pot=50; // You can declare global variables in javascript

function roll2d6 () {
  return Math.floor(Math.random() * 6)   Math.floor(Math.random() * 6)   2;
}

function takebet (betvalue) {
  // And here you place the logic, checking the bet against the remaining pot, rolling again if they need to match, etc. etc.
}

</script>

auroraChloe

*sighs*      why are geek brains such a turn on? 

a/a 8/21/17