Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
8039136
completed initial test scripts, still need to make roulette and check…
BrennanFulmer Nov 20, 2017
846c7bd
resolved merge conflict
BrennanFulmer Nov 20, 2017
8ef4b74
first commit on new VM
BrennanFulmer Nov 22, 2017
9764286
Merge branch 'master' of github.com:BrennanFulmer/assignment_js_sprint
BrennanFulmer Nov 22, 2017
16d1276
rewrote loud snake case to be more human readable
BrennanFulmer Nov 27, 2017
2e31ac9
now with barebones version of roulette game
BrennanFulmer Nov 27, 2017
3647725
first functional roulette game (just needs bells/whistles), and seper…
BrennanFulmer Nov 28, 2017
3660c2b
modified README text so it won't display weird in Github
BrennanFulmer Nov 28, 2017
f9315f8
reworded README to be clearer
BrennanFulmer Nov 28, 2017
2e3a000
improved scripts.js with more conventional formatting and again rewro…
BrennanFulmer Nov 28, 2017
03640df
again rewrote README, but this time to simplify
BrennanFulmer Nov 28, 2017
619b34a
making improvements to Roulette game to handle more user inputs
BrennanFulmer Nov 29, 2017
af27f58
completed part 1 of roulette assignment
BrennanFulmer Nov 29, 2017
02109c1
renamed Roulette launching html file for clarity
BrennanFulmer Nov 29, 2017
f9937db
removed some redundancies and improved function names for clarity
BrennanFulmer Nov 29, 2017
82d3c3b
commiting to save before making changes to incorporate non-number bet…
BrennanFulmer Nov 29, 2017
60f96ac
now possible to make special bets, and made functions independent of …
BrennanFulmer Nov 29, 2017
933b566
now capable of handling special bets through the whole script
BrennanFulmer Nov 30, 2017
af16d46
improved user input handling, implemented modularization, added comme…
BrennanFulmer Nov 30, 2017
2115a18
Update README.md
BrennanFulmer Nov 30, 2017
b080d75
Update README.md
BrennanFulmer Nov 30, 2017
ccded94
incredibly small tweaks
BrennanFulmer Nov 30, 2017
2e54434
reworded readme
BrennanFulmer Nov 30, 2017
d4a6727
fixed a few tiny problems that were bothering me
BrennanFulmer Dec 1, 2017
66e69d0
implemented assignment operators
BrennanFulmer Dec 3, 2017
b39088b
Update README.md
BrennanFulmer Mar 8, 2018
9b62ce9
Update README.md
BrennanFulmer Mar 8, 2018
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
4 changes: 4 additions & 0 deletions Basic_Problems/jquery-1.11.1.min.js

Large diffs are not rendered by default.

102 changes: 102 additions & 0 deletions Basic_Problems/scripts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
var sprintFunctions = {
// takes an array and returns the largest element.
largestEl: function(array) {
var highest = 0,
counter = 0;
while (counter < array.length) {
if (highest < array[counter]) {
highest = array[counter];
}
counter += 1;
}
return highest;
},

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

/*takes a full sentence and puts it into "Loud_Snake_Case" format but strips
out any non-character elements (like punctuation).*/
loudSnakeCase: function(sentence) {
return sentence
.toLowerCase()
.replace(/[^A-Za-z ]/g, "")
.replace(/ +/g, " ")
.replace(/\b./g, function(firstLetter) {
return firstLetter.toUpperCase();
})
.replace(/ /g, "_");
},

/*takes two arrays and checks to see if they are equal (same contents in the
same order). Assume they're not nested.*/
compareArrays: function(array1, array2) {
return array1.join(",") === array2.join(",");
},

/*takes an input of a number and returns an array containing all the elements
from 1 to that number. Each element divisible by 3 is replaced by "FIZZ", each
element divisible by 5 is replaced by "BUZZ" and each element divisible by
both 3 and 5 is replaced by "FIZZBUZZ". Eg. fizzBuzz(6) => [ 1, 2, "FIZZ", 4,
"BUZZ", "FIZZ" ]*/
fizzBuzz: function(number) {
var count = 1,
patternoutput = [];
while (count <= number) {
if (count % 3 === 0 && count % 5 === 0) {
patternoutput.push("FIZZBUZZ");
} else if (count % 3 === 0) {
patternoutput.push("FIZZ");
} else if (count % 5 === 0) {
patternoutput.push("BUZZ");
} else {
patternoutput.push(count);
}
count += 1;
}
return patternoutput;
},

/*takes an array and a function. It passes every element from the array into
that function, in turn, running the function. The returned array should be
filled with each of the return statements from that function.*/
myMap: function(AnArray, aFunction) {
return AnArray.map(aFunction);
},

/*takes a number and outputs an array containing all prime numbers that occur
prior to that number, e.g. primes(8) => [2,3,5,7]*/
primes: function(aNumber) {
if (aNumber > 2) {
var options = [],
increment = 2;
while (increment < aNumber) {
if (increment % 2 !== 0 || increment === 2) {
options.push(increment);
}
increment += 1;
}
function findPrime(integer) {
var check = integer - 1,
primey = true;
while (check > 1) {
if (integer % check === 0) {
primey = false;
break;
}
check -= 1;
}
return primey;
}
var primes = options.filter(findPrime);
return primes;
} else {
return options;
}
}
};
1 change: 0 additions & 1 deletion scripts_spec.js → Basic_Problems/scripts_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,5 @@ var tester = {

}


$(document).ready( function(){ tester.init( sprintFunctions )});

211 changes: 211 additions & 0 deletions Bigger_Problems/roulette.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,211 @@
/*
1. Build a Roulette game using basic object-oriented programming principles in
JavaScript. The user should start with a bankroll and bet with each "spin" of
the imaginary wheel. They can choose numbers 1-36. After each spin, the result
is displayed and funds are distributed accordingly (payout is 35:1). Gameplay
might look something like:

r = new Roulette( 100 ) // starting bankroll $100
r.spin( 10, 24 ) // bet 10 on 24
// You Win $350, the spin was 24!!!
// You now have $440.
r.spin( 50, 13 )
// You Lose, the spin was 11 :(
// You now have $390
r.bankroll()
// You now have $390
r.buyIn( 1000 )
// You bought in $1000
// You now have $1390

2. Add the ability for users of your Roulette game to bet on "0" (35:1),
"00" (35:1), "Even" (1:1), "Odd" (1:1), "1 to 18" (1:1), "19 to 36" (1:1),
"1st 12" (2:1), "2nd 12" (2:1), or "3rd 12" (2:1).
*/

var bankroll = 100;

while (bankroll > 0) {
var bet;
var target;

// this function asks users to input how much they'd like to bet, processes that input to make sure its valid and returns the result in the bet variable
function betting() {
bet = prompt(
"Please enter how much you'd like to bet.\nCurrent bankroll is $" +
bankroll +
"."
);
if (Number(bet.replace(/\D/g, "")) === 0) {
alert("Please enter your bet in number form and or above zero.");
betting();
} else if (bet.replace(/\-/, "") !== bet || bet.replace(/\./, "") !== bet) {
alert("Please enter a positive number without a decimal.");
betting();
} else if (bankroll < Number(bet.replace(/\D/g, ""))) {
bet = bankroll;
alert(
"Since you can't bet above bankroll your bet has been set to $" +
bankroll +
"."
);
} else {
bet = Number(bet.replace(/\D/g, ""));
}
return bet;
}

// this function requests what the user wants to bet on, again makes some input checks to ensure validity, and returns the result in the target variable
function targetting() {
target = prompt(
"Enter what number you'd like to bet on between 0 and 36, winners get 35 times their bet.\nAlternatively you can bet on the following options to potentially double your bet.\n00\nEven\nOdd\n1 to 18\n19 to 36\n1st 12\n2nd 12\n3rd 12"
);
target = target.toLowerCase();
if (
target === "00" ||
target === "even" ||
target === "odd" ||
target === "1 to 18" ||
target === "19 to 36" ||
target === "1st 12" ||
target === "2nd 12" ||
target === "3rd 12"
) {
} else if (target.replace(/\D/g, "") === "") {
alert(
"Please enter what you'd like to bet on as a number such as 10 or use one of the special bet types like even."
);
targetting();
} else if (
target.replace(/\-/, "") !== target ||
target.replace(/\./, "") !== target
) {
alert("Please enter a whole number equal to or above 0 and below 37.");
targetting();
} else if (36 < Number(target.replace(/\D/g, ""))) {
alert("Please enter a number below 37.");
targetting();
} else {
target = Number(target.replace(/\D/g, ""));
}
return target;
}

/* this function processes the actual bet's result so it generates a random value to compare against their bet target,
modifies their bankroll based on the result, and provides a summary of the entire bet cycle*/
function spinning() {
var wheel = [
"00",
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12,
13,
14,
15,
16,
17,
18,
19,
20,
21,
22,
23,
24,
25,
26,
27,
28,
29,
30,
31,
32,
33,
34,
35,
36
];
var spin = wheel[Math.floor(Math.random() * wheel.length)];

//
/*
*/
console.log("ba " + bankroll + " be " + bet + " ta " + target + " spin " + spin);
/*
*/
//

if (target === spin) {
bankroll = bankroll - bet + bet * 35;
} else if (target === "even" && spin % 2 === 0) {
bankroll = bankroll - bet + bet * 2;
} else if (target === "odd" && spin % 2 !== 0) {
bankroll = bankroll - bet + bet * 2;
} else if (target === "1 to 18" && spin < 19) {
bankroll = bankroll - bet + bet * 2;
} else if (target === "19 to 36" && spin > 18) {
bankroll = bankroll - bet + bet * 2;
} else if (target === "1st 12" && spin < 13) {
bankroll = bankroll - bet + bet * 2;
} else if (target === "3rd 12" && spin > 23) {
bankroll = bankroll - bet + bet * 2;
} else if (target === "2nd 12" && spin > 11 && spin < 25) {
bankroll = bankroll - bet + bet * 2;
} else {
bankroll -= bet;
}

alert(
"You bet $" +
bet +
".\n" +
"The bet was on " +
target +
".\n" +
"The spin result was " +
spin +
".\n" +
"Your bankroll is now $" +
bankroll +
"."
);
return bankroll;
}

// this function simply asks a user if they'd like to raise their bankroll, does some checks to confirm their input is good, and processes the result on their bankroll
function buyingIn() {
var buyIn = prompt(
"If you'd like to increase your bankroll enter by how much.\nOtherwise enter 0."
);
if (buyIn.replace(/\D/g, "") === "") {
alert(
"Please enter how much you'd like to increase your bankroll by as a number such as 500."
);
buyingIn();
} else if (
buyIn.replace(/\-/, "") !== buyIn ||
buyIn.replace(/\./, "") !== buyIn
) {
alert("Please enter a positive number without a decimal.");
buyingIn();
} else {
buyIn = Number(buyIn.replace(/\D/g, ""));
bankroll += buyIn;
}
return bankroll;
}

betting();
targetting();
spinning();
buyingIn();
}
10 changes: 10 additions & 0 deletions Bigger_Problems/roulette_shell.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<html>
<head>
<meta charset="utf-8">
<title>Roulette - its not pretty but neither is Vegas</title>
<script src="roulette.js"></script>
</head>
<body>
<h1>I hope you enjoyed this simple Roulette game, reload to play again.</h1>
</body>
</html>
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
assignment_js_sprint
====================

while(1){ go() };
by Brennan Fulmer

This is primarily a test driven development project where I had to write Javascript code to solve supplied tests. The Bigger Problems folder contains a nearly pure Javascript based Roulette game, as the html file in that folder is only for user interaction. I may at some point come back to improve the GUIs, but for now the purpose of the assignment is just to learn Javascript.

Javascript Tests:
https://brennanfulmer.github.io/assignment_js_sprint/

Roulette Game (warning this creates popups for user interaction):
https://brennanfulmer.github.io/Roulette/
11 changes: 6 additions & 5 deletions index.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<html>
<head>
<script src="https://code.jquery.com/jquery-1.11.1.min.js"></script>
<script src="scripts.js"></script>
<script src="scripts_spec.js"></script>
<meta charset="utf-8">
<script src="Basic_Problems/jquery-1.11.1.min.js"></script>
<script src="Basic_Problems/scripts.js"></script>
<script src="Basic_Problems/scripts_spec.js"></script>
<style>
h1,h2,h3,p{
text-align: center;
Expand All @@ -16,7 +17,7 @@
</style>
</head>
<body>
<h1>
<h1>
Javascript Sprint Test Suite
</h1>

Expand Down Expand Up @@ -72,4 +73,4 @@ <h3>
Pending...
</div>
</body>
</html>
</html>
Loading