Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

slot machine solution #263

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions slushmachine.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
.slot {
border: 1px solid black;
padding: 20px;
text-align: center;
height: 400px;
width: 100%;
justify-content: center;
align-items: center;
}

.reel {
display: inline-block;
margin: 0 10px;
font-size: 24px;
width: 50%;
height: 40px;
}

button {
font-size: 20px;
margin-top: 20px;
}

21 changes: 21 additions & 0 deletions slushmachine.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="slushmachine.css" >
<title>Slush Machine</title>
</head>
<body>
<div class = "slot">
<div class="reel" id="slot1"></div>
<div class="reel" id="slot2"></div>
<div class="reel" id="slot3"></div>
<p id="msg"></p>
<button id="maxBet">Big Spin</button>
<button id="minBet">Little Spin</button>
<p id="wallet"></p>
</div>
<script src="slushmachine.js"></script>
</body>
</html>
113 changes: 113 additions & 0 deletions slushmachine.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
//user plays a game of randomizing
//key values hoping to match three items in the spinwheel

//collection of values to randomize
let orange = 0
let mandarin = 1
let apple = 2
let kiwi = 3
let banana = 4

function getFruit(num) {
switch (num) {
case 0: return 'Orange';
case 1: return 'Mandarin';
case 2: return 'Apple';
case 3: return 'Kiwi';
case 4: return 'Banana';
}
}

//bets and wallet activities
let min = 5
let max = 50
let wallet = 1000

//event listeners
document.querySelector('#minBet').addEventListener('click', minSpin)
document.querySelector('#maxBet').addEventListener('click', maxSpin)
document.querySelector('#wallet').innerText = wallet

//code for randomization
function randoNum(){
return Math.floor(Math.random() * 5)
}
console.log(randoNum())


//code to compare win lose conditions

function minSpin(){

let slot1 = randoNum();
let slot2 = randoNum();
let slot3 = randoNum();

document.getElementById('slot1').innerText = getFruit(slot1);
document.getElementById('slot2').innerText = getFruit(slot2);
document.getElementById('slot3').innerText = getFruit(slot3);

wallet -= min;

if(slot1 === slot2 && slot2 === slot3){
document.getElementById('msg').innerText = 'You Win!';
wallet += 50
} else {
document.getElementById('msg').innerText = 'Try Again';
}
document.getElementById ('wallet').innerText = wallet;

return
}

function maxSpin(){

let slot1 = randoNum();
let slot2 = randoNum();
let slot3 = randoNum();

document.getElementById('slot1').innerText = getFruit(slot1);
document.getElementById('slot2').innerText = getFruit(slot2);
document.getElementById('slot3').innerText = getFruit(slot3);

wallet -= max;

if(slot1 === slot2 && slot2 === slot3){
document.getElementById('msg').innerText = 'You Win!';
wallet += 500
} else {
document.getElementById('msg').innerText = 'Try Again';
}

document.getElementById ('wallet').innerText = wallet;

return
}


//website shows slot machine with two bet options and a wallet
//min bet=$5
//max bet=$50
//wallet=$1,000

//user can play min bet
//website slot machine takes in $5 --> wallet - $5
//website slot machine shows new amount
//website slot machine plays bet
//if user win wallet goes up but by how much???
//website slot machine prints message 'You won'
//if user lose wallet goes down -$5
//wesbite slot machine prints message 'Try again'

//user can play max bet
//website slot machine takes in $50 --> wallet - $50
//website slot machine shows new amount
//website slot machine plays bet
//if user win wallet goes up but by how much???
//website slot machine prints message 'You won'
//if user lose wallet goes down -$50
//wesbite slot machine prints message 'Try again'

//user play new game
//website slot machine shows new game option