From 71ef154c236a3356926905ef3512c878e65c3ea6 Mon Sep 17 00:00:00 2001 From: hicx76 Date: Sat, 7 Oct 2017 15:11:39 -0600 Subject: [PATCH 1/2] Finished JS tests, all return TRUE. --- scripts.js | 76 +++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 61 insertions(+), 15 deletions(-) diff --git a/scripts.js b/scripts.js index bbbb844..3da5ab7 100644 --- a/scripts.js +++ b/scripts.js @@ -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; }, } \ No newline at end of file From 13302403302396172722f865a2e747f4bd97623a Mon Sep 17 00:00:00 2001 From: hicx76 Date: Mon, 9 Oct 2017 08:40:23 -0600 Subject: [PATCH 2/2] Made roulette game. Still fixing cashroll update. --- roulette.js | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 roulette.js diff --git a/roulette.js b/roulette.js new file mode 100644 index 0000000..8e4c431 --- /dev/null +++ b/roulette.js @@ -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();