Skip to content
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
85 changes: 85 additions & 0 deletions roulette.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
function Roulette(initialAmount) {
this.bankAmount = initialAmount;

this.bankroll = function () {
console.log("You now have $" + this.bankAmount);
};

this.getPocket = function () {
this.pocket = Math.round(Math.random()*37);
if(this.pocket == 37)
this.pocket = "00";
};

this.lose = function (amount) {
this.bankAmount -= amount;
console.log("You Lose, the spin was " + this.pocket + ".");
console.log("You now have $" + this.bankAmount);
};

this.win = function (amount, multiplier) {
this.payout = amount * multiplier;
this.bankAmount += this.payout;
console.log("You Win $" + this.payout +", the spin was " + this.pocket + "!!!");
console.log("You now have $" + this.bankAmount);
};

this.spin = function (amount, bet) {
if(amount > this.bankAmount) {
console.log("You don't have sufficient balance.");
}
else {
this.payout = 0;
this.getPocket();

switch(bet){
case "Even":
if (this.pocket % 2 === 0 && this.pocket > 0)
this.win(amount, 1);
break;

case "Odd":
if (this.pocket % 2 !== 0)
this.win(amount, 1);
break;

case "1 to 18":
if (this.pocket >= 1 && this.pocket <= 18)
this.win(amount, 1);
break;

case "19 to 36":
if (this.pocket >= 19 && this.pocket <= 36)
this.win(amount, 1);
break;

case "1st 12":
if (this.pocket >= 1 && this.pocket <= 12)
this.win(amount, 2);
break;

case "2nd 12":
if (this.pocket >= 13 && this.pocket <= 24)
this.win(amount, 2);
break;

case "3rd 12":
if (this.pocket >= 25 && this.pocket <= 36)
this.win(amount, 2);
break;

default:
if(bet === this.pocket)
this.win(amount, 35);
}
if (this.payout == 0)
this.lose(amount);
}
};

this.buyIn = function (amount) {
console.log("You bought in $" + amount);
this.bankAmount += amount;
console.log("You now have $" + this.bankAmount);
};
}
95 changes: 77 additions & 18 deletions scripts.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,91 @@
// FILL IN THE FUNCTIONS BELOW

var sprintFunctions = {
largestEl: function(){
// your code here
},

reversed: function(){
// your code here
largestEl: function(arr){
var largest = arr[0]
for(i = 1; i < arr.length; i++)
if(largest < arr[i])
largest = arr[i]
return largest
},

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

compareArrays: function(){
// your code here (replace the return)
return "Finish compareArrays first!"
loudSnakeCase: function (sentence){
return sentence
.replace(/[^A-Za-z ]/g,"")
.replace(/\s+/g, " ")
.split(" ")
.map(function(word) {
return word[0].toUpperCase() + word.substr(1);
})
.join("_");
},

fizzBuzz: function(){
// your code here
compareArrays: function(arr1, arr2){
if(arr1.length != arr2.length)
return false;
else {
for(var i = 0; i < arr1.length; i++)
if(arr1[i] != arr2[i])
return false;
}
return true;
},

myMap: function(){
// your code here
fizzBuzz: function(max){
var result = [];
for(var i = 1; i <= max; i++){
var output = "";
if(i % 3 == 0)
output += "FIZZ";

if(i % 5 == 0)
output += "BUZZ";

if(output=="")
output = i;

result.push(output);
}
return result;
},

primes: function(){
// your code here
myMap: function(arr, func){
var new_arr = [];
arr.forEach(function(elem){
new_arr.push(func(elem));
});
return new_arr;
},
}

primes: function(num){

// Sieve of Eratosthenes Algorithm

var sieve = [];

for(var i = 2; i < num; i++)
sieve[i] = true;

var limit = Math.sqrt(num);

for(var i = 2; i < limit; i++) {
if(sieve[i]) {
for(var j = i * i; j < num; j += i)
sieve[j] = false;
}
}
var prime_arr = [];
sieve.forEach(function (isPrime, index) {
if(isPrime)
prime_arr.push(index);
})
return prime_arr;
}
}