diff --git a/README.md b/README.md
index 4f9c999..475a5cc 100644
--- a/README.md
+++ b/README.md
@@ -2,3 +2,4 @@ assignment_js_sprint
====================
while(1){ go() };
+Tzvi Seliger
\ No newline at end of file
diff --git a/index.css b/index.css
new file mode 100644
index 0000000..745ce09
--- /dev/null
+++ b/index.css
@@ -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;
+}
diff --git a/index.html b/index.html
index 2aa3713..b6572e2 100644
--- a/index.html
+++ b/index.html
@@ -1,5 +1,6 @@
+
@@ -40,7 +41,6 @@
Pending...
-
Compare Arrays:
@@ -64,12 +64,56 @@
Pending...
-
Primes:
Pending...
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/open b/open
new file mode 100644
index 0000000..e69de29
diff --git a/roulette b/roulette
new file mode 100644
index 0000000..e69de29
diff --git a/roulette.js b/roulette.js
new file mode 100644
index 0000000..30678ec
--- /dev/null
+++ b/roulette.js
@@ -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()
+})
+
diff --git a/scripts.js b/scripts.js
index bbbb844..2f37e46 100644
--- a/scripts.js
+++ b/scripts.js
@@ -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
+ }
}
\ No newline at end of file