Skip to content

Instantly share code, notes, and snippets.

View macikokoro's full-sized avatar

Joaquin Guardado macikokoro

View GitHub Profile
@macikokoro
macikokoro / oddSquare.html
Last active August 29, 2015 14:02
For loop to print squares of odd numbers between 100 and 150 and ignore even numbers.
<script>
for (var i = 100; i <=150; i++) {
if (i % 2 == 1) {
console.log (i * i);
}
else {
console.log (i);
}
}
</script>
@macikokoro
macikokoro / blastOff.js
Created June 15, 2014 08:31
for loop to countdown from 10 to 0 and print Blast off!
for (var i = 10; i >= 0; i--) {
console.log(i);
if (i === 0) {
console.log("Blast Off!");
}
}
@macikokoro
macikokoro / function.js
Created June 15, 2014 09:14
Example of a javaScript function.
function () {
console.log("hi");
};
//The following calls the function
hi();
@macikokoro
macikokoro / subString.js
Created June 15, 2014 19:15
A cool way to use substrings to capitalize the first letter of a name.
var fullName = "";
var name;
var firstLetter;
var fixName = function () {
}
name = prompt("Enter your first name (all in lower case):");
@macikokoro
macikokoro / parameter.js
Created June 15, 2014 19:52
Example of a function that uses parameters to do an action.
var sayHelloTo = function (name) {
console.log("Hello " + name);
};
sayHelloTo("Kokoro");
@macikokoro
macikokoro / arguments.js
Last active August 29, 2015 14:02
Function with parameter ( ) and argument { }
var identity = function (x) {
return x;
};
@macikokoro
macikokoro / evenOrOdd.js
Created June 15, 2014 20:39
Code to check for odd or even numbers
var isOdd = function (n) {
if (n % 2 === 0) {
return false;
} else {
return true;
}
};
console.log(isOdd(1));
console.log(isOdd(2));
@macikokoro
macikokoro / arrayLoop.js
Last active August 29, 2015 14:02
Array and loop combination
var lost = [4, 8, 15, 16, 23, 42];
var count = lost.length;
var isLost = function (n) {
for (var i = 0; i < 6; i++ ) {
if ( n === lost[i]) {
return true;
}
}
return false;
@macikokoro
macikokoro / not.js
Created June 19, 2014 07:46
Function to check if a number is a multiple of 3 and a function to check for the opposite.
var isMultipleOfThree = function (x) {
return x % 3 === 0;
};
var isNotMultipleOfThree = function (x) {
return !isMultipleOfThree(x);
};
@macikokoro
macikokoro / power.js
Created June 19, 2014 08:33
Function to find out the power of a number.
var power = function (base, exponent) {
var result = 1;
for (var i = 0; i < exponent; i++) {
result = result * base;
}
return result;
};
power(2, 2);