-
-
Save thedillonb/c20a2ff322c6519e4511 to your computer and use it in GitHub Desktop.
// source http://jsbin.com/dimana/2
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> | |
<meta charset="utf-8"> | |
<title>JS Bin</title> | |
</head> | |
<body> | |
<a href = "#" onclick="calculate()"> | |
Calculate life time supply | |
</a> | |
<br><br> | |
<a href = "#" onclick="favoriteThings()"> Show favorites </a> | |
<br><br> | |
<a href = "#" onclick="myFriends()"> Show my friends </a> | |
<script> | |
function calculate (){ | |
var myAge = 41; | |
var myMaxAge = 129; | |
var myCoffeesPerDay = 2; | |
var daysPerYear = 365; | |
var lifetimeSupplyOfCoffee = (myMaxAge - myAge) * daysPerYear * myCoffeesPerDay; | |
console.log("You will need "+lifetimeSupplyOfCoffee+" coffees to last until your old age of "+myMaxAge); | |
if (lifetimeSupplyOfCoffee > 40000){ | |
console.log("Wow! That's a lot!"); | |
} else { | |
console.log("You seem pretty reasonable!"); | |
} | |
} | |
function favoriteThings () { | |
var favorites = ["Dogs", "Cats", "Bears", "Tigers"]; | |
var theAlertText = "My favorite things are"; | |
for (var i=0; i<favorites.length; i++) { | |
console.log(favorites[i]); | |
if (i<favorites.length-1) { | |
theAlertText = theAlertText + " " +favorites[i]+","; | |
} | |
else { | |
theAlertText = theAlertText + " and " +favorites[i]+"."; | |
} | |
} | |
alert (theAlertText); | |
} | |
var pet = charlie.pet; | |
var pet = charlie ["pet"]; | |
charlie.gender = "male"; | |
var peanuts = [ | |
{name: "Charlie Brown", pet: "Snoopy"}, | |
{name: "Linus van Pelt", pet: "Blue Blanket"} | |
]; | |
function myFriends () { | |
var friends = [ | |
{name: "Maria", hair: "red"}, | |
{name: "Jimmy", hair: "pink"}, | |
{name: "Marsha", hair: "brown"} | |
]; | |
for (var i = 0; i < friends.length; i++) { | |
var friend = friends[i]; | |
console.log(friend.name + " has " + friend.hair + " hair."); | |
} | |
} | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment