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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ assignment_js_sprint
====================

while(1){ go() };

Holly Erickson's answers
74 changes: 74 additions & 0 deletions bigger_problems.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
var bankroll,
bet,
gamble,
land,
addBank,
increase,
cashOut,
start = 100;

//sets up starting bankroll
var newRoulette = function() {
bankroll = start;
alert("Your starting bankroll is $" + bankroll);
}

//explain rules and payout of game
var rules = function() {
alert("You can choose a number from 1-36. The payout is 35:1.");
}

//allows player to add more money
var moreMoney = function(){
increase = Number(prompt("How much would you like to add? Please enter a number without the $ sign"));
bankroll = bankroll + increase;
alert("You now have $" + bankroll);
}

//collects the players bet, amount they are gambling and spins the winning number
var spin = function(){
bet = Number(prompt("Would would you like to bet on?\nChoose a number 1 - 36."));
gamble = Number(prompt("How much would you like to bet?\nYou have $" + bankroll));
land = Math.floor(Math.random()* 36 + 1);

//if player loses, bet subtracted from bankroll
if(land != bet){
bankroll = bankroll - gamble;
alert("You lose, the spin was " + land);
}

//if player wins, bet * 35 added to bankroll
else if(land == bet){
bankroll = bankroll + (gamble * 35);
alert("You win! Your bankroll just increased by $" + (gamble*35));
}

//gmae over when money is gone
if (bankroll < 1){
alert("GAME OVER");
return;

//option to cash out and end game
} else {
cashOut = confirm("You now have $" + bankroll + ". Would you like to keep playing?");
if (!cashOut) {
alert("Thanks for playing!");
return;
}

//option to buyin more money and game continues
addBank = confirm("Would you like to buy in?");
if (addBank) {
moreMoney();
}
spin();
}
}

//starts the game
var check = confirm("Would you like to play roulette?");
if (check) {
newRoulette();
rules();
spin();
}
113 changes: 95 additions & 18 deletions scripts.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,109 @@
// FILL IN THE FUNCTIONS BELOW

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

//takes an array and returns the largest element
largestEl: function(array){
array.sort();
return array[array.length - 1];
},

reversed: function(){
// your code here

// takes a string and reverses it
reversed: function(string){
var arr = string.split("");
arr = arr.reverse();
return arr.join("");
},

loudSnakeCase: function(){
// your code here
/* Takes a full sentence and puts it into "Loud_Snake_Case"
strips out any non-character elements (like punctuation) */
loudSnakeCase: function(str){
var arr = str.toLowerCase().replace(/\s{2,}/g, ' ').split(' ');

for (i = 0; i < arr.length; i++) {
arr[i] = arr[i].match(/[^\W]+/g).join('');
arr[i] = arr[i].charAt(0).toUpperCase() + arr[i].slice(1);
}

var newStr = arr.join('_');
return newStr;

},

compareArrays: function(){
//takes two arrays and checks to see if they are equal (same contents in the same order)
compareArrays: function(arr1, arr2){
// your code here (replace the return)
return "Finish compareArrays first!"
},
var check = true;

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

myMap: function(){
// your code here
return check;
},

primes: function(){
// your code here
/* takes number input and returns array containing all the elements from 1 to number
Each element divisible by both 3 and 5 is replaced by "FIZZBUZZ"
Each element divisible by 3 is replaced by "FIZZ"
Each element divisible by 5 is replaced by "BUZZ"*/
fizzBuzz: function(num){
var arr = new Array();

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

return arr;
},
}

/*takes an array and a function.
passes every element from the array into that function, in turn, running the function
returned array should be filled with each of the return statements from that function.*/
myMap: function(arr, fun){

var newArr = arr.map(function(el){
return fun(el);
});

return newArr;
},

//takes a number and outputs an array containing all prime numbers that occur prior to that number
primes: function(limit){
var arr = new Array();

for (var counter = 2; counter <= limit; counter++) {

var notPrime = false;
for (var i = 2; i <= counter; i++) {
if (counter%i===0 && i!==counter) {
notPrime = true;
}
}
if (notPrime === false) {
arr.push(counter);
}
}

return arr;
},

}