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
58 changes: 58 additions & 0 deletions roulette.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
var r = {
startingBank: 100,
guess: 0,
bet: 0,
outcome: 0,
placeBet: function(){
this.bet = parseInt(prompt("Place your bets!!!"));
return this.bet;
},
guessNum: function(){
this.guess = parseInt(prompt("Choose your number..."));
return this.guess;
},
spin: function(){
this.outcome = Math.floor(Math.random() * 39);
console.log("The winning number is " + this.outcome);
},
compare: function(){
if(r.guess === r.outcome){
this.bankRoll = this.bankRoll + this.bet;
console.log("You WIN!");
console.log("Now you have $" + this.bankRoll);
return this.bankRoll;
} else {
this.bankRoll = this.bankRoll - this.bet;
console.log("You lost.");
console.log("Now you have $" + this.bankRoll);
return this.bankRoll;
}
},
checkBank: function(){
if(this.bankroll <= 0){
console.log("You lost all your money!");
}
},
anotherGame: function(){
answer= parseInt(prompt("Play another round? Y/N?"));
if(answer === N || answer === n){
playAgain = false;
} else {
play();
}
},
play: function(){
bankRoll = this.startingBank;
playAgain = true;
while(playAgain === true){
r.placeBet();
r.guessNum();
r.spin();
r.compare();
r.checkBank();
}
},
}


r.play();
76 changes: 61 additions & 15 deletions scripts.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,78 @@
// FILL IN THE FUNCTIONS BELOW

var sprintFunctions = {
largestEl: function(){
// your code here
largestEl: function(arr){
arr.sort().reverse();
return arr[0];
},

reversed: function(){
// your code here
reversed: function(str){
var backwards = str.split("").reverse().join("");
return backwards;
},

loudSnakeCase: function(){
// your code here
loudSnakeCase: function(str){
var imASnake = str.replace(/[^\w\s]/gi, '').replace(" ", " ").split(' ');
for (var i = 0; i < imASnake.length; i++) {
imASnake[i] = imASnake[i].charAt(0).toUpperCase() + imASnake[i].slice(1);
};
return imASnake.join('_');
},

compareArrays: function(){
// your code here (replace the return)
return "Finish compareArrays first!"
compareArrays: function(arr1, arr2){
var length = 0;
if (arr1.length === arr2.length){
length = arr1.length;
} else {
console.log("Compare similar lists!")
}
var isEqual = false;
for(i = 0; i < length; i++){
if(arr1[i] === arr2[i]) {
isEqual = true;
} else {
isEqual = false;
}
}
return isEqual;
},

fizzBuzz: function(){
// your code here
fizzBuzz: function(num){
var array = [];
for (i = 1; i < num + 1; i++) {
if(i % 5 === 0 && i % 3 === 0){
array.push("FIZZBUZZ");
} else if (i % 5 === 0) {
array.push("BUZZ");
} else if (i % 3 === 0) {
array.push("FIZZ");
} else {
array.push(i);
}
}
return array;
},

myMap: function(){
// your code here
myMap: function(arr){
var finalArray = arr.map(function(val){
return val * 2;
});
return finalArray;
},

primes: function(){
// your code here
primes: function(num){
var primeList = [];
for (n = 2; n <= num; n++) {
var notPrime = false;
for (var i = 2; i <= n; i++) {
if (n % i === 0 && i !== n) {
notPrime = true;
}
}
if (notPrime === false) {
primeList.push(n);
}
}
return primeList;
},
}