Jump to content
Sign in to follow this  
  • entries
    3
  • comments
    0
  • views
    233

Slot machine

MarklHarrison9

487 views

This program emulates a slot machine. 

Slot.png.96f76342ed3bdff7127c5ec48d876428.png

 

using math it will pick a random number 3 times and put it into a variable X Y and Z.

var x = Math.floor((Math.random() * 5) + 1);
var y = Math.floor((Math.random() * 5) + 1);
var z = Math.floor((Math.random() * 5) + 1);

If you hit the win button you are guaranteed a win, Lose button you're guaranteed a loss. this was for debugging purposes.

Winning causes you to win your bid amount x 2.

function win(){
var bid = document.getElementById("BidID").value;
    document.getElementById("res").innerHTML = "yay you win";
	Coins= Coins+bid*2;
    document.getElementById("coinID").innerHTML = "Total Coins = " +Coins;
	document.getElementById("payout").innerHTML = "Won "+bid*2+" coins!!!";
}

It will also display "yay you win" in the element named res.

Whole Code can be found below.

<!DOCTYPE html>
<html>
<body>

<input type="number" id="BidID" value="0">

<p>Click the button to start slots match 2 and you win yay~.</p>

<button onclick="myFunction()">Click me</button>
<button onclick="win()">Win</button>
<button onclick="lose()">Lose</button>

<p id="coinID">
<p id="res">
<p id="demo">
<p id="demo2">
<p id="demo3">
<p id="payout"></p>


<script>
var Coins=100;
    document.getElementById("coinID").innerHTML = "Total Coins = " +Coins;
function myFunction() {
var x = Math.floor((Math.random() * 5) + 1);
var y = Math.floor((Math.random() * 5) + 1);
var z = Math.floor((Math.random() * 5) + 1);
var bid = document.getElementById("BidID").value;
if(bid > 0 && bid< Coins){
    document.getElementById("demo").innerHTML = x;
    document.getElementById("demo2").innerHTML = y;
    document.getElementById("demo3").innerHTML = z;

if(x==y || x==z || y==z){
var bid = document.getElementById("BidID").value;
    document.getElementById("res").innerHTML = "yay you win";
	Coins= Coins+bid*2;
    document.getElementById("coinID").innerHTML = "Total Coins = " +Coins;
	document.getElementById("payout").innerHTML = "Won "+bid*2+" coins!!!";
}
else {
var bid = document.getElementById("BidID").value;
    document.getElementById("res").innerHTML = "Boo you lose";
	Coins= Coins-bid;
    document.getElementById("coinID").innerHTML = "Total Coins = " +Coins;
    document.getElementById("payout").innerHTML = "lost "+bid+" coins";
}

}
else{
document.getElementById("res").innerHTML = "you have to bid more then 0 - . -; or less then max coins";
}
}

function win(){
var bid = document.getElementById("BidID").value;
    document.getElementById("res").innerHTML = "yay you win";
	Coins= Coins+bid*2;
    document.getElementById("coinID").innerHTML = "Total Coins = " +Coins;
	document.getElementById("payout").innerHTML = "Won "+bid*2+" coins!!!";
}

function lose(){
var bid = document.getElementById("BidID").value;
    document.getElementById("res").innerHTML = "Boo you lose";
	Coins= Coins-bid;
    document.getElementById("coinID").innerHTML = "Total Coins = " +Coins;
    document.getElementById("payout").innerHTML = "lost "+bid+" coins";
	
}


</script>

</body>
</html>

 

 



0 Comments


Recommended Comments

There are no comments to display.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!