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

assignment completed #133

Open
wants to merge 4 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
60 changes: 60 additions & 0 deletions roulette.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
var bankroll = 100,
repeat = true,
wheel = [];
for (var i=0; i < 37; i++){
wheel.push(`${i}`);
}
wheel.push('00');
var valid_bets = wheel.concat(["Even","Odd","1 to 18", "19 to 36", "1st 12", "2nd 12", "3rd 12"]);


while (bankroll > 0 && repeat === true){
//placing bet amount
var bet_amount = prompt(`Your bankroll is currently $${bankroll}. How much would you like to bet?`);
bet_amount = Number(bet_amount)+0;

while (isNaN(bet_amount)) {
bet_amount = prompt(`That is not a valid bet. Please place a bet between $1 and your currrent bankroll of $${bankroll}.`);
bet_amount = Number(bet_amount)+0;
}

//placing bet
var lucky_number = prompt(`$${bet_amount} on which number(s)? [0-36, 00, Even, Odd, 1 to 18, 19 to 36, 1st 12, 2nd 12, 3rd 12]`);
while (valid_bets.includes(lucky_number) === false) {
lucky_number = prompt(`That is not a valid bet. Please place a valid bet. [0-36, 00, Even, Odd, 1 to 18, 19 to 36, 1st 12, 2nd 12, 3rd 12]`);
lucky_number = Number(lucky_number)+0;
}

//spin
var actual_number = wheel[Math.floor(Math.random()*wheel.length)];
alert(`Roll lands on number ${actual_number} and you bet on ${lucky_number}.`);

//settling up
if (lucky_number === actual_number) {
bankroll = bankroll + (bet_amount * 35);
alert(`Congratulations! You won ${bet_amount*35} and your balance is now $${bankroll}.`);
// 1:1 payouts
} else if (lucky_number === "Even" && actual_number % 2 === 0 || lucky_number === "Odd" && actual_number % 2 !== 0 ||
lucky_number === "1 to 18" && wheel.slice(1,19).includes(actual_number) ||
lucky_number === "19 to 36" && wheel.slice(19,37).includes(actual_number) ) {
bankroll = bankroll + bet_amount;
alert(`Congratulations! You won ${bet_amount} and your balance is now $${bankroll}.`);
// 2:1 payouts
} else if (lucky_number === "1st 12" && wheel.slice(1,13).includes(actual_number) ||
lucky_number === "2nd 12" && wheel.slice(12,25).includes(actual_number) ||
lucky_number === "3rd 12" && wheel.slice(25,37).includes(actual_number) ){
bankroll = bankroll + (bet_amount * 2);
alert(`Congratulations! You won ${bet_amount} and your balance is now $${bankroll}.`);
} else {
bankroll = bankroll - bet_amount;
alert(`I'm sorry, you lose! Your balance is now $${bankroll}.`)}


//again?
repeat = confirm("Would you like to continue?");
if (repeat === false){
alert("Thanks for playing!");}
else if (repeat === true && bankroll < 1) {
bankroll = prompt(`I'm sorry, your bankroll is currently $${bankroll}. How much would you like to buy in?`);
}
}
135 changes: 115 additions & 20 deletions scripts.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,127 @@
// FILL IN THE FUNCTIONS BELOW

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

reversed: function(){
// your code here
largestEl: function(arr){
arr = arr.sort();
return arr[arr.length-1];
},

loudSnakeCase: function(){
// your code here
reversed: function(str){
var result = []
for (var i = 0; i < str.length; i++) {
result.unshift(str[i]);
}
return result.join('');
},

compareArrays: function(){
// your code here (replace the return)
return "Finish compareArrays first!"
},
loudSnakeCase: function(str){
var words = str.split(' '),
punctuation = '!,.;:-',
result = [],
result2 = [];

fizzBuzz: function(){
// your code here
},
// elminates multiple consecutive spaces
words = words.filter(function(word){
return word.length > 0;
});


words.forEach(function(word){
var letters = word.split(''),
temp = [];

letters.forEach(function(letter,index){
if (punctuation.includes(letter) === false){
if (index === 0) {
temp.push(letter.toUpperCase());
} else {
temp.push(letter.toLowerCase());
}
}
});

myMap: function(){
// your code here
result.push(temp.join(''));
});

return result.join('_');
},

primes: function(){
// your code here
compareArrays: function(arr1,arr2) {
var answer = true;

arr1.forEach(function(element,index){
if (arr1[index] !== arr2[index]) {
answer = false;
}
});

return answer;
},
}

fizzBuzz: function(n) {
var result = [];

for (i=1; i < n+1; i++) {
if (i % 5 === 0 && i % 3 === 0) {
result.push("FIZZBUZZ");
} else if (i % 5 === 0) {
result.push("BUZZ");
} else if (i % 3 === 0) {
result.push("FIZZ");
} else
result.push(i);
}

return result;
},

myMap: function(arr,func) {
var result = [];

arr.forEach(function(element) {
result.push(func(element));
});

return result;
},

primes: function(n) {

//helper function to test for primality
var isPrime = function (n){
if (n < 2) {
return false;
}

//creating range
var range = [];
for (var i = 2; i < n; i++) {
range.push(i);
}

var prime = true;

//checking for primality
range.forEach(function(divisor){
if (n % divisor === 0) {
prime = false;
}
});

return prime;
}

//checking all numbers from 2 to input parameter
var result = [];
if (n < 2) {
return result;
} else
for (var i = 2; i < n; i++) {
if (isPrime(i)) {
result.push(i);
}
}

return result;
},
}