This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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."); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>DOM Demo - Attributes</title> | |
<style type="text/css"> | |
#form1.embiggen #user_name { | |
font-size: 300%; | |
} | |
</style> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (typeof(Array.isArray) !== 'function') { | |
Array.isArray = function(value) { | |
return Array.prototype.toString.apply(value) === '[object Array]'; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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!"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var mj = { | |
first: 'Michael', | |
last: 'Jordan', | |
number: 23, | |
position: 'SG', | |
active: false | |
}; | |
// get a property | |
console.log(mj.number); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var add = function() { | |
var sum = 0; | |
for (var i = 0; i < arguments.length; i++) { | |
sum += arguments[i]; | |
} | |
return sum; | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>JavaScript Demo - Remove DOM Elements & Replace Text</title> | |
</head> | |
<body> | |
<section id="main"> | |
<header> | |
<h1>Space Ghost</h1> | |
<h2>Coast to Coast</h2> |