Skip to content

Instantly share code, notes, and snippets.

View ashryanbeats's full-sized avatar
🔋

Ash Ryan Arnwine ashryanbeats

🔋
View GitHub Profile
var countDown = function(starter) {
if (starter === 0) {
return starter;
}
else {
console.log(starter);
return countDown(--starter);
}
}
@ashryanbeats
ashryanbeats / gist:2834125
Created May 30, 2012 06:41
Rock paper scissors
var result = "";
var player = prompt("Pick rock, paper, or scissors.");
if(player !== null){
player = player.toLowerCase();
}
var choices = ["rock","paper","scissors"];
var computer = choices[Math.floor(Math.random()*3)];
@ashryanbeats
ashryanbeats / gist:2833770
Created May 30, 2012 04:24
Combine 2 arrays into 1 2D array
//array 1: the suits
var suits = ["clubs","hearts","diamonds","spades"];
//array 2: the ranks
var ranks = [2,3,4,5,6,7,8,9,10,"J","Q","K","A"];
var deck = [];
for(i=0; i<suits.length; i++){
for(j=0; j<ranks.length; j++){
@ashryanbeats
ashryanbeats / FizzBuzz++: Return of the Modulus
Created May 7, 2012 04:58
FizzBuzz++: Return of the Modulus
var FizzBuzzPlus={
isFizzBuzzie: function(n){
if((n%3===0 || n%5===0) && !(n%3===0 && n%5===0)){
return true;
} else {
return false;
}
},
getFizzBuzzSum: function(max){
var sum = 0;
@ashryanbeats
ashryanbeats / Nested conditionals
Created February 25, 2012 02:47
Introduction to objects 1.3
for(i=1; i<=20; i++){
var result = i;
if(i%3===0){
if(i%5===0){
console.log("FizzBuzz");
} else {
console.log("Fizz");
}
} else if(i%5===0){
console.log("Buzz");
@ashryanbeats
ashryanbeats / 2.7
Created February 21, 2012 02:08
Blackjack
var deal = function() {
card = Math.floor(Math.random()*52+1);
return card;
};
var card1 = deal();
var card2 = deal();
var getValue = function(card) {
if(card % 13 === 0 || card % 13 > 10){
@ashryanbeats
ashryanbeats / Cheaper options?
Created February 18, 2012 02:16
Conditionals in Javascript Project 2.6
var calculateTotalCosts = function(salary,numWorkers,city){
var fixedCosts = 5000;
var variableCosts = salary*numWorkers;
if(city === "NYC"){
return fixedCosts+variableCosts+30000;
} else if(city === "BEJ"){
return fixedCosts+variableCosts+25000;
} else {
return fixedCosts+variableCosts+10000;
}
@ashryanbeats
ashryanbeats / Location, location
Created February 18, 2012 02:12
Conditionals in Javascript Project 2.5
var calculateTotalCosts = function(salary,numWorkers,city){
var fixedCosts = 5000;
var variableCosts = salary*numWorkers;
if(city === "NYC"){
return fixedCosts+variableCosts+30000;
} else {
return fixedCosts+variableCosts;
}
}
@ashryanbeats
ashryanbeats / Dice game
Created February 17, 2012 02:50
Conditionals in Javascript Project
var die1 = Math.floor(Math.random()*6 + 1);
var die2 = Math.floor(Math.random()*6 + 1);
var score;
if(die1 === 1 || die2 === 1){
score = 0
} else {
if(die1 === die2){
score = die1+die2*2
} else {
@ashryanbeats
ashryanbeats / Setting values using a ternary operator
Created February 17, 2012 02:20
Conditionals in Javascript 5.4
var food = prompt("What's for dinner?")
foodType = food === "taco" ? "Mexican" : "other";