Skip to content

Instantly share code, notes, and snippets.

@benwillkommen
Created March 25, 2014 16:50
Show Gist options
  • Save benwillkommen/9766146 to your computer and use it in GitHub Desktop.
Save benwillkommen/9766146 to your computer and use it in GitHub Desktop.
<html>
<head>
<title>My Site!</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.3.min.js"></script>
<script src="main.js"></script>
</head>
<body>
<div id="friendMessage"></div>
<a id="calculationLink" href="#" onclick="calculate()">dust calculation</a>
<a href="#" onclick="favoriteThings()">favorite things</a>
<a href="#" onclick="myFriends()">friends</a>
</body>
</html>
function myFriends(){
//declare array of friend objects, with your friends name and hair color
var friends = [
{name: "josh", hair: "black", age: 8, sayHi: function(){alert("hello");}},
{name: "clair", hair: "brown"}
];
var message = "my friends are ";
//iterate over the friends array using a for loop
for(var i = 0; i < friends.length; i++){
message = message + friends[i].name + " whose hair color is " + friends[i].hair + ", "
}
var messageDiv = document.getElementById("friendMessage");
messageDiv.innerHTML = message;
}
function favoriteThings(){
var myFavoriteThings = ["javascript", "game of thrones", "squaresoft RPGs", "lifting heavy things"];
var message = "My favorite things are ";
for (var i = 0; i<myFavoriteThings.length; i++){
if(i == myFavoriteThings.length-1){
message = message + " and " + myFavoriteThings[i] + ".";
}
else{
message = message + myFavoriteThings[i] + ", ";
}
}
alert(message);
}
function calculate(){
var age = 27;
var deadAt = 138;
var proteinDustPerDay = 3;
var totalDustIntake = (deadAt - age) * 365 * proteinDustPerDay;
var message = "";
if(totalDustIntake > 40000){
message = 'wow, that\'s alot of dust!';
}
else {
message = "that's a reasonable amount of dust.";
}
alert(message);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment