Skip to content

Instantly share code, notes, and snippets.

@katherineschultz
Created October 14, 2014 00:59
Show Gist options
  • Save katherineschultz/0fba14b9e45e98e49b57 to your computer and use it in GitHub Desktop.
Save katherineschultz/0fba14b9e45e98e49b57 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>
<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"];
for (var i=0; i<favorites.length; i++) {
console.log(favorites[i]);
}
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment