Skip to content

Instantly share code, notes, and snippets.

@thedillonb
Forked from katherineschultz/index.html
Last active August 29, 2015 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thedillonb/c20a2ff322c6519e4511 to your computer and use it in GitHub Desktop.
Save thedillonb/c20a2ff322c6519e4511 to your computer and use it in GitHub Desktop.
<!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