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
120 changes: 120 additions & 0 deletions roulette.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
var bankroll = prompt("How much would you like to start with as your bank?");

while (bankroll > 0) {
var wager = prompt("Enter your wager amount (dollars you'd like to bet) as an integer");
var betInteger = prompt("Place your bet. Type: odd or even, 1 to 18, 19 to 36, 1st 12, 2nd 12, 3rd 12, or whole numbers including 0, 00, or a single number from 1 - 36.");

function roulette (wager, betInteger) {
this.wager = parseInt(wager);
this.bankroll = parseInt(bankroll);
// this.betInteger = parseInt(betInteger);
if (bankroll < wager) {
alert("You do not have $" + wager + " to spend. Please select an amount less than or equal to " + bankroll + ".");
} else if ((betInteger > 36) || (betInteger < 0)) {
alert("That is not an appropriate bet. Please place your bet by typing 'odd', 'even', '1 to 18', '19 to 36', '1st 12', '2nd 12', '3rd 12', or entering numbers including 0, 00, 1 - 36.");
} else {
var spin = Math.floor(Math.random() * 36);
if ( ( betInteger == "00") && (spin == 0) ) {
bankroll += ( +wager * 35 );
alert ("You win $" + (wager * 35) + ". You bet on " + betInteger + " and the spin matched. You now have $" + bankroll + ".");
} else if (betInteger == spin) {
bankroll += ( +wager * 35 );
alert ("You win $" + (wager * 35) + " . You now have $" + bankroll + ". Your bet was " + betInteger + " and the spin was " + spin + ".");
} else if (betInteger == "even") {
if (spin % 2 == 0) {
bankroll = (+bankroll + +wager);
alert ("You win $" + wager + ". The spin was " + spin + " which is even. You now have $" + bankroll + ".");
} else {
bankroll = (bankroll - wager);
if (bankroll == 0) {
alert("You lose, the spin was " + spin + " which is odd. You are all out of money. Thank you so much for playing!");
} else {
alert ("You lose $" + wager + ". The spin was " + spin + " which is odd. You now have $" + bankroll + ".");
}
}
} else if (betInteger == "odd") {
if (spin % 2 != 0) {
bankroll = (+bankroll + +wager);
alert ("You win $" + wager + ". The spin was " + spin + " which is odd. You now have $" + bankroll + ".");
} else {
bankroll -= wager;
if (bankroll == 0) {
alert("You lose, the spin was " + spin + " which is even. You are all out of money. Thank you so much for playing!");
} else {
alert ("You lose $" + wager + ". The spin was " + spin + " which is even. You now have $" + bankroll + ".");
}
}
} else if (betInteger == "1 to 18") {
if (spin <= 18) {
bankroll = (+bankroll + +wager);
alert ("You win $" + wager + ". The spin was " + spin + " which is between 1-18. You now have $" + bankroll + ".");
} else if (spin > 18) {
bankroll -= wager;
if (bankroll == 0) {
alert("You lose, the spin was " + spin + " which is not between 1-18. You are all out of money. Thank you so much for playing!");
} else {
alert ("You lose $" + wager + ". The spin was " + spin + " which is not between 1-18. You now have $" + bankroll + ".");
}
}
} else if (betInteger == "19 to 36") {
if (spin > 18) {
bankroll = (+bankroll + +wager);
alert ("You win $" + wager + ". The spin was " + spin + " which is between 19-36. You now have $" + bankroll + ".");
} else if (spin <= 18) {
bankroll -= wager;
if (bankroll == 0) {
alert("You lose, the spin was " + spin + " which is not between 19-36. You are all out of money. Thank you so much for playing!");
} else {
alert ("You lose $" + wager + ". The spin was " + spin + " which is not between 19-36. You now have $" + bankroll + ".");
}
}
} else if (betInteger == "1st 12") {
if (spin <= 12) {
bankroll = (bankroll + (wager*2));
alert ("You win $" + (wager*2) + ". The spin was " + spin + " which is between 1-12. You now have $" + bankroll + ".");
} else if (spin > 12) {
bankroll -= wager;
if (bankroll == 0) {
alert("You lose, the spin was " + spin + " which is not between 1-12. You are all out of money. Thank you so much for playing!");
} else {
alert ("You lose $" + wager + ". The spin was " + spin + " which is not between 1-12. You now have $" + bankroll + ".");
}
}
} else if (betInteger == "2nd 12") {
if (spin <= 24) {
bankroll = (bankroll + (wager*2));
alert ("You win $" + (wager*2) + ". The spin was " + spin + " which is between 13-24. You now have $" + bankroll + ".");
} else if ((spin >= 25) || (spin <= 12)) {
bankroll -= wager;
if (bankroll == 0) {
alert("You lose, the spin was " + spin + " which is not between 13-24. You are all out of money. Thank you so much for playing!");
} else {
alert ("You lose $" + wager + ". The spin was " + spin + " which is not between 13-24. You now have $" + bankroll + ".");
}
}
} else if (betInteger == "3rd 12") {
if (spin > 25) {
bankroll = (bankroll + (wager*2));
alert ("You win $" + (wager*2) + ". The spin was " + spin + " which is between 25-36. You now have $" + bankroll + ".");
} else if (spin < 36) {
bankroll -= wager;
if (bankroll == 0) {
alert("You lose, the spin was " + spin + " which is not between 25-36. You are all out of money. Thank you so much for playing!");
} else {
alert ("You lose $" + wager + ". The spin was " + spin + " which is not between 25-36. You now have $" + bankroll + ".");
}
}
} else {
bankroll -= wager;
if (bankroll == 0) {
alert("You lose. You bet " + betInteger + "; the spin was " + spin + ". You are all out of money. Thank you so much for playing!");
} else {
alert ("You lose. You bet " + betInteger + "; the spin was " + spin + ". You now have $" + bankroll + ".");
}
}
}
return bankroll;
} roulette(wager, betInteger);
}


115 changes: 97 additions & 18 deletions scripts.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,111 @@
// FILL IN THE FUNCTIONS BELOW


var sprintFunctions = {
largestEl: function(){
// your code here
largestEl: function () {
return Math.max.apply(Math, input);
},

reversed: function(){
// your code here
},

loudSnakeCase: function(){
// your code here
reversed: function(){
return input.split("").reverse().join("");
},

compareArrays: function(){
// your code here (replace the return)
return "Finish compareArrays first!"
loudSnakeCase: function(){
//remove punctuation
input = input.replace(/[.,\/#!$%\^&\*;:{}=\-_`~()]/g,"");
//remove any extra spaces
input = input.replace(/ +/g, ' ');
//proper case
input = input.toLowerCase().replace(/\b[a-z]/g, function(letter) {
return letter.toUpperCase();
});
//replace spaces with underscores
input = input.replace(/\s/g,'_');
return input;
},

fizzBuzz: function(){
// your code here
compareArrays: function(){
// "startArr" vs "diffArr"
//check they are the same length
var i = startArr.length;
if (i != diffArr.length) {
return false;
}
//check each value
while (i--) {
if (startArr[i] !== diffArr[i]) {
return false;
}
}
return true;
},

myMap: function(){
// your code here


fizzBuzz: function(){
let arr = [];
for (let x = 1; x <= input; x++) {
arr.push(x);
}
let fizzArr = []; //added new array to return at the end
for (let i = 0; i < arr.length; i++) {
if ( ( arr[i] % 5 == 0 ) && ( arr[i] % 3 == 0 ) ) {
fizzArr.push("FIZZBUZZ");
}
else if ( arr[i] % 5 == 0 ) {
fizzArr.push("BUZZ");
}
else if ( arr[i] % 3 == 0 ) {
fizzArr.push("FIZZ");
}
else {
fizzArr.push(arr[i]);
}
} return fizzArr; //return here only.
},
//was using return for each if/else condition, resulting in the script ending prematurely.

//original function - doesn't work
myMap: function(){
inputArr.map(inputFunc);
},

//var inputArr = [1,2,3,4,5];
//var inputFunc = function(el){ return el*2; };

//new function
myMap: function(inputArr, inputFunc) {
for (var i = 0; i < inputArr.length; i++) {
inputArr[i] = func(inputArr[i]);
}
return inputArr;
},

//I still don't really understand. I thought the whole point of the .map method was to not have to create a new array or push the values to the new array.




primes: function(input){
// did not know a good way to check for prime value

primes: function(){
// your code here
//liked this solution the best
//create new array to return later
let primesArr = [];
// incrementally cycle through numbers up to value of the input variable
for ( let i=1; i <= input; i++ ) {
// incrementally cycle through numbers lower than the current value being checked
for ( let j=(i-1); j >= 1; j-- ) {
// if the divisor is 1, push to the array
if ( j === 1 ) {
primesArr.push(i);
// but if a number doesn't leave a remainder, then skip it
} else if ( i % j === 0 ) {
break;
}
}
}
//return the array of only primes
return primesArr;
},
}
}