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

Project Finished #149

Open
wants to merge 3 commits 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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ assignment_js_sprint
====================

while(1){ go() };
Tzvi Seliger
44 changes: 44 additions & 0 deletions index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
html {
font-family: Arial;
font-size: 14px;
color: green;
}

.playeraction {
width:50px;
height:50px;
background: blue;
border-radius: 20px;
font-size: 10px;
color: white;
text-align: center;
padding:1.1em;
}

.inline {
display: inline-block;
}

label {
background: yellow;
border-radius: 10px;
padding: 1.2em;
}

input[type = "submit"] {
background: green;
}

.form {
border-radius: 10px;
padding: 1.2em;
margin: 1.2em;
}

.orange {
background: orange;
}

.green {
background: green;
}
48 changes: 46 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<html>
<head>
<link rel = 'stylesheet' type ="text/css" href = "index.css">
<script src="https://code.jquery.com/jquery-1.11.1.min.js"></script>
<script src="scripts.js"></script>
<script src="scripts_spec.js"></script>
Expand Down Expand Up @@ -40,7 +41,6 @@ <h3>
<div class="output" id="loud-snake-case">
Pending...
</div>

<h3>
Compare Arrays:
</h3>
Expand All @@ -64,12 +64,56 @@ <h3>
<div class="output" id="my-map">
Pending...
</div>

<h3>
Primes:
</h3>
<div class="output" id="primes">
Pending...
</div>


<div class = "form green">
<div class = "form orange">
<form>
<ul>
<li class = "inline">
<label for = "betAmount">set bet amount</label>
<input type = "text" id = "betAmount" class = "playeraction"></input></li>
<li class = "inline"> <label for = "betNumber">set bet number</label>
<input type = "text" id = "betNumber" class = "playeraction"></input></li>
<li class = "inline"><label for = "betType">set bet type</label>
<input type = "text" id = "betType" class = "playeraction"></input></li>
<li class = "inline"><label for = "buyInAmount">set buyin amount</label>
<input type = "text" id = "buyInAmount" class = "playeraction"></input></li>
<li class = "inline"><div id = "setAll" class = "playeraction">Set All</div></li>
</ul>
</form>
</div>


<div class= "form orange" >
<ul>
<li class = "inline"><div id = "roll" class = "playeraction">roll</div></li>
<li class = "inline"><div id = "showcash" class = "playeraction">showcash</div></li>
</ul>
</div>

<div class= "form orange" >
<div id = "player1stats" >
<div id = "player1money" class = "playeraction inline"></div>
<div id = "player1lastbet" class = "playeraction inline"></div>
<div id = "player1lastresult" class = "playeraction inline"></div>
</div>
<div id = "player2stats">
<div id = "player2money" class = "playeraction inline"></div>
<div id = "player2lastbet" class = "playeraction inline"></div>
<div id = "player2lastresult" class = "playeraction inline"></div>
</div>
</div>
</div>



<script src = "roulette.js"></script>
</body>
</html>
Empty file added open
Empty file.
Empty file added roulette
Empty file.
138 changes: 138 additions & 0 deletions roulette.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
let index = 1,
players = {},
player = {
betAmount: 0,
betNumber: 1,
betType: "",
buyInAmount: 100,
setBetAmount:function(betAmount){
this.betAmount = parseInt(betAmount)
},
setBetNumber:function(betNumber){
this.betNumber = parseInt(betNumber)
},
setBetType:function(betType){
this.betType = parseInt(betType)
},
setBuyInAmount:function(buyInAmount){
this.cash += parseInt(buyInAmount)
},
cash: 0
}

player.__proto__.buyIn = function() {
this.cash += this.buyInAmount
this.showCash()
}
player.__proto__.roll = function() {
var rolled = Math.round(Math.random() * 36)
player.rolled = rolled
var match = ""
let type = document.getElementById("betType").value
if (this.betNumber === "") {
switch (type) {
case "even":
if (rolled % 2 === 0) {
match = true
}
break;
case "odd":
if (rolled % 2 !== 0) {
match = true;
}
break;
case "1 to 18":
if (rolled > 0 && rolled < 18) {
match = true;
}
break;
case "19 to 36":
if (rolled > 18 && rolled < 37) {
match = true;
}
break;
case "1st 12":
if (rolled > 0 && rolled < 13) {
match = true;
}
break;
case "2nd 12":
if (rolled > 12 && rolled < 25) {
match = true;
}
break;
case "3rd 12":
if (rolled > 24 && rolled < 37) {
match = true;
}
break;
}
console.log(match, this.betNumber, rolled)
} else {
this.betNumber <= 36 ? console.log(match, this.betNumber, rolled) : console.log(`${this.betNumber} too large`)
match = this.betNumber === rolled
}
if(match){
this.cash += this.betAmount
console.log( `you won ${this.betAmount}, ${this.cash} is your new total` )
} else {
this.cash -= this.betAmount;
console.log( `you lost ${this.betAmount}, ${this.cash} is your new total` );
}
}

player.__proto__.showCash = function() {
console.log(this)
console.log(this.cash)
}
while (index < 3) {
players["player" + index] = Object.create(player)
index++
}
let {
player1,
player2
} = players


let currentPlayer = player1
let currentIdmoney = "player1money"
let currentIdbet = "player1lastbet"
let currentIdresult = "player1lastresult"

function changePlayer(){
if(currentPlayer === player1){
currentPlayer = player2
currentIdmoney = "player2money"
currentIdbet = "player2lastbet"
currentIdresult = "player2lastresult"
} else {
currentPlayer = player1
currentIdmoney = "player1money"
currentIdbet = "player1lastbet"
currentIdresult = "player1lastresult"
}
}

$("#setAll").click(function(){
currentPlayer.setBetAmount(document.getElementById("betAmount").value)
currentPlayer.setBetNumber(document.getElementById("betNumber").value)
currentPlayer.setBetType( document.getElementById("betType").value)
currentPlayer.setBuyInAmount(document.getElementById("buyInAmount").value)
})

$("#buyin").click(function(){
currentPlayer.buyIn()
})
$("#roll").click(function(){
currentPlayer.roll()
$(`#${currentIdmoney}`).html(currentPlayer.cash)
$(`#${currentIdbet}`).html(currentPlayer.betNumber)
$(`#${currentIdresult}`).html(currentPlayer.rolled)
changePlayer()

})
$("#showcash").click(function(){
currentPlayer.showCash()
})

102 changes: 86 additions & 16 deletions scripts.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,102 @@
// FILL IN THE FUNCTIONS BELOW

var sprintFunctions = {
largestEl: function(){
largestEl: function( array ){
// your code here
let i = 0;
let largest = 0;
while ( i < array.length ){
if ( array[i] > largest ){
largest = array[i];
}
i += 1;
}
return largest;
},

reversed: function(){
reversed: function( string ){
// your code here
var str = "";
var i = string.length - 1;
while ( i >= 0 ){
str += string[i];
i -= 1;
}
return str;
},

loudSnakeCase: function(){
loudSnakeCase: function( sentence ){
// your code here
var chars = /[^A-Za-z\s0-9]/g;
var capArray = function (sentence){
return sentence.map( function(item){
return item[0].toUpperCase() + item.slice(1)
})
}
var add = function( sentence, match, separator ){
return sentence.replace( match, separator )
}
loudSnakeCaseWorks = add( capArray( sentence.replace(/\s\s+/, " ").replace(chars, "").split(" ") ).join(" "), /\s/g, "_")
return loudSnakeCaseWorks
},

compareArrays: function(){
compareArrays: function(arr1, arr2){
// your code here (replace the return)
return "Finish compareArrays first!"
let index = 0;
let equal = true;
while (index < arr1.length) {
if ( arr1[ index ] !== arr2[ index ]) {
equal = false;
}
index += 1;
}
// your code here ( replace the return )
return equal;
},

fizzBuzz: function(){
fizzBuzz: function( number ){
// your code here
let numbers = [];
let index = 1;
while ( index <= number ) {
if ( index % 3 === 0 && index % 5 !== 0 ){
numbers.push( "FIZZ" );
} else if ( index % 5 === 0 && index % 3 !== 0 ){
numbers.push( "BUZZ" );
} else if ( index % 3 === 0 && index % 5 === 0 ){
numbers.push( "FIZZBUZZ" );
} else {
numbers.push( index );
}
index += 1;
}
return numbers;
},

myMap: function(){
myMap: function( array, func ){
// your code here
let newArray = []
array.forEach( function( item ){
newArray.push( func( item ) )
} )
return newArray
},

primes: function(){
primes: function( choice ){
// your code here
},
var decarray = function(number){
var array = []
while( number > 1 ){
array.push( number )
number --
}
return array
}
var prime = function(number){
var match = number - 1;
var isPrime = true;
while( match > 1){
if (number % match === 0){
isPrime = false
}
match --
}
return isPrime
}
let filtered = decarray(choice).filter(prime).reverse()
return filtered
}
}