You are either not logged in or not registered with our community. Click here to register.

April 16, 2021, 11:37:22 pm

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length

Click here if you are having problems.
Default Wide Screen Beige Lilac Rainbow Black & Blue October Platinum Send us your theme!

### Author Topic: Java HALP  (Read 861 times)

0 Members and 1 Guest are viewing this topic.

#### Adonis  ##### Java HALP
« on: December 16, 2009, 09:10:07 pm »
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>

#### Vekseid ##### Re: Java HALP
« Reply #1 on: December 17, 2009, 09:30:23 am »
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
Code: [Select]
`<script type="text/javascript">var pot=50; // You can declare global variables in javascriptfunction 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 ##### Re: Java HALP
« Reply #2 on: December 17, 2009, 09:48:29 am »
*sighs*      why are geek brains such a turn on?