Skip to content

Instantly share code, notes, and snippets.

View macikokoro's full-sized avatar

Joaquin Guardado macikokoro

View GitHub Profile
@macikokoro
macikokoro / powerFunction.js
Created June 20, 2014 03:52
Function to calculate the power of a number.
var power = function(base, exponent) {
if (exponent === 0) {
return 1;
}
else {
return base * power (base, exponent - 1);
}
};
@macikokoro
macikokoro / cube.js
Created June 20, 2014 04:11
function to find the cube of a number.
// Accepts a number x as input and returns its square
var square = function (x) {
return x * x;
};
// Accepts a number x as input and returns its cube
var cube = function (x) {
return x * x *x;
};
@macikokoro
macikokoro / taxiFare.js
Created June 20, 2014 06:00
Function arguments to calculate a taxi ride.
// calculates taxi fare based upon miles traveled
// and the hour of the day in military time (0-23).
var taxiFare = function (milesTraveled, pickupTime) {
var baseFare = 2.50;
var costPerMile = 2.00;
var nightSurcharge = 0.50; // 8pm to 6am, every night
var cost = baseFare + (costPerMile * milesTraveled);
// add the nightSurcharge to the cost if it is after
@macikokoro
macikokoro / quarterDivisible.js
Created June 20, 2014 07:11
Function to check if the quarter of a number is divisible by three.
var quarter = function(number) {
return number/4;
}
if (quarter(24) % 3 === 0 ) {
console.log("The statement is true");
} else {
console.log("The statement is false");
}
@macikokoro
macikokoro / rockPaperScissors.html
Created June 20, 2014 09:24
Rock, Paper, Scissors Game.
<script>
//The Game
//Each player chooses either rock, paper or scissors
//Rock destroys scissors
//Scissors cut paper
//Paper covers rock
//Phases
//1. User makes a choice
//2. Computer makes a choice
@macikokoro
macikokoro / whileSheep.js
Last active August 29, 2015 14:03
While loop with multiplication.
var numSheep = 4;
var monthNumber = 1;
var monthsToPrint = 12;
while(monthNumber <= monthsToPrint) {
numSheep *= 4;
console.log("There will be " + numSheep + " sheep after " + monthNumber + " month(s)!");
monthNumber++;
}
@macikokoro
macikokoro / forLoop.js
Last active August 29, 2015 14:03
For loop example
/* Syntax of a for loop:
for ( *start with this* ; *loop if this expression is true* ; *do this after each loop*) {
* in each loop, d this code!*
}
In order (initialize; check condition; control the loop) */
//Not operational cars
var carsOperational = 10;
var totalCars = 14;
for (var stoppedCar = carsOperational + 1; stoppedCar <= totalCars; stoppedCar++ ) {
@macikokoro
macikokoro / whileLoop.js
Last active August 29, 2015 14:03
While loop example.
var totalCars = 10;
var carsOperational = 8;
var carNumber = 1;
while(carNumber <= carsOperational) {
console.log("Car #" + carNumber + " is running.");
carNumber++;
}
@macikokoro
macikokoro / whileAndFor.js
Last active August 29, 2015 14:03
While loop and for loop combo.
var totalCars = 10;
var carsOperational = 8;
var carNumber = 1;
while(carNumber <= carsOperational) {
console.log("Car #" + carNumber + " is running.");
carNumber++;
}
for( var stoppedCar = carsOperational + 1; stoppedCar <= totalCars; stoppedCar++) {
@macikokoro
macikokoro / descending.js
Last active August 29, 2015 14:03
For loop example to print descending numbers.
for(var number = 6; number > 0; number--) {
console.log(number);
}