Lottery
by nukeboy212
HTML
<div>
<h2 id="mon1">
Player One Money: $20
</h2>
<button id="buy1">
Buy a ticket
</button>
<h2 id="onenum">
</h2>
</div>
<div>
<h2 id="mon2">
Player Two Money: $20
</h2>
<button id="buy2">
Buy a ticket
</button>
<h2 id="twonum">
</h2>
</div>
<div>
<h2 id="mon3">
Player Three Money: $20
</h2>
<button id="buy3">
Buy a ticket
</button>
<h2 id="threenum">
</h2>
</div>
<h3 id="h33">
Jackpot is:
</h3>
<button id="roll">
Roll
</button>
<h1>
Ticket has been placed for:
</h1>
CSS
#h33 {
margin-top: 100px;
}
h2 {
display: inline;
}
#buy1 {
margin-left: 15px;
}
#buy2 {
margin-left: 15px;
}
#buy3 {
margin-left: 15px;
}
#roll {
margin-left: 300px;
}
JavaScript
changingjackpot();
function changingjackpot() {
var jackpot = Math.floor(Math.random() * 1000) + 100;
$("#h33").text("Jackpot is: $" + jackpot)
}
setInterval(function() {
changingjackpot();
}, 10000)
var tickedplaced = false
var playerone = 20
var playertwo = 20
var playerthree = 20
var ticketbought1 = false;
var ticketbought2 = false;
var ticketbought3 = false;
var playeronenum = ""
var playertwonum = ""
var playerthreenum = ""
setInterval(function() {
$("#mon1").text("Player One Money: $" + playerone)
$("#mon2").text("Player Two Money: $" + playertwo)
$("#mon3").text("Player Three Money: $" + playerthree)
}, 100);
setInterval(function() {
$("#onenum").text(playeronenum)
$("#twonum").text(playertwonum)
$("#threenum").text(playerthreenum)
}, 100);
$("#buy1").click(function() {
if (ticketbought1 == false) {
playerone--;
playeronenum = Math.floor(Math.random() * 31) + 1
ticketbought1 = true
} else {
alert("You already bought a ticket")
}
})
$("#buy2").click(function() {
if (ticketbought2 == false) {
playertwo--;
playertwonum = Math.floor(Math.random() * 31) + 1
ticketbought2 = true }
else {
alert("You already bought a ticket")
}
})
$("#buy3").click(function() {
if (ticketbought3 == false) {
playerthree--;
playerthreenum = Math.floor(Math.random() * 31) + 1
ticketbought3 = true;
} else {
alert("You already bought a ticket")
}
})