Skip to content

Instantly share code, notes, and snippets.

View jpetto's full-sized avatar
🪐

J Petto jpetto

🪐
View GitHub Profile
@jpetto
jpetto / javascript_branching.js
Created August 25, 2012 22:44
JavaScript branching example
var s = Number(prompt("How old are you?"));
if (s <= 10) {
console.log("You're a young one!");
} else if (s <= 20) {
console.log("Those rowdy teen years...");
} else if (s <= 30) {
console.log("You got time, don't worry.");
} else {
console.log("Over 30? Man, hurry up and do something with your life.");
@jpetto
jpetto / dom_demo_2.html
Created August 25, 2012 23:13
DOM Demo #2
<!DOCTYPE html>
<html>
<head>
<title>DOM Demo - Attributes</title>
<style type="text/css">
#form1.embiggen #user_name {
font-size: 300%;
}
</style>
@jpetto
jpetto / javascript_is_array.js
Created August 26, 2012 16:52
JavaScript isArray
if (typeof(Array.isArray) !== 'function') {
Array.isArray = function(value) {
return Array.prototype.toString.apply(value) === '[object Array]';
}
}
@jpetto
jpetto / javascript_loops_example.js
Created August 26, 2012 20:14
JavaScript loops example
var coffees = ['Ethiopia', 'Rwanda', 'Burundia', 'Kenya', 'Tanzania'];
for (var i = 0; i < coffees.length; i++) {
console.log(coffees[i]);
}
var pip = Number(prompt("What was Pippen's jersey number?"));
while (pip !== 33) {
alert("Wrong!");
@jpetto
jpetto / javascript_array_example.js
Created August 26, 2012 20:17
JavaScript array example
var coffees = ['Ethiopia', 'Burundi', 'Costa Rica', 'Guatemala'];
console.log(coffees.length);
console.log("My favorite coffee is from " + coffees[1] + ".");
// change the second coffee in the array
coffees[1] = 'Brazil';
console.log(coffees);
@jpetto
jpetto / javascript_array_methods_1.js
Created August 26, 2012 20:25
JavaScript array methods - 1
var coffees = ['Ethiopia', 'Rwanda', 'Burundia', 'Kenya', 'Tanzania'];
var coffee_string = coffees.join(", ");
console.log(coffee_string);
// removes the last element in the array and stores it in last
var last = coffees.pop();
console.log(last);
@jpetto
jpetto / javascript_object_properties.js
Created August 28, 2012 16:31
JavaScript object properties
var mj = {
first: 'Michael',
last: 'Jordan',
number: 23,
position: 'SG',
active: false
};
// get a property
console.log(mj.number);
@jpetto
jpetto / javascript_functions_first_class.js
Created August 30, 2012 14:44
JavaScript functions - first class objects
/*
Functions are first class objects, which means you can:
- store them in a variable
- store them in an array
- pass them as an argument to a function
- return them from a function
*/
// store a function in a variable
var smart_play = function(num) {
@jpetto
jpetto / javascript_functions_arguments.js
Created August 30, 2012 15:01
JavaScript functions - arguments example
var add = function() {
var sum = 0;
for (var i = 0; i < arguments.length; i++) {
sum += arguments[i];
}
return sum;
};
@jpetto
jpetto / dom_demo_remove_elements_change_text.html
Created August 31, 2012 00:39
DOM Demo - Remove elements & change text
<!DOCTYPE html>
<html>
<head>
<title>JavaScript Demo - Remove DOM Elements &amp; Replace Text</title>
</head>
<body>
<section id="main">
<header>
<h1>Space Ghost</h1>
<h2>Coast to Coast</h2>