Created
April 30, 2014 23:20
-
-
Save benwillkommen/f7d84911e17a5217e61a to your computer and use it in GitHub Desktop.
This file contains 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
<html> | |
<head> | |
<title>My Site!</title> | |
</head> | |
<body> | |
<img id="mainpicture" src="http://girldevelopit.com/assets/pink-logo.png"> | |
<br/> | |
<a href="#" onclick="favoriteThings()"> | |
Favorite Things | |
</a> | |
<br/> | |
<a href="#" onclick="doKitty()"> | |
kitty | |
</a> | |
<br/> | |
<a href="#" onclick="calculate()"> | |
calculate | |
</a> | |
<script src="myjavascriptfile.js"></script> | |
</body> | |
</html> |
This file contains 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
function doKitty(){ | |
var img = document.getElementById('mainpicture'); | |
img.setAttribute("src", "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTJRrHzINNAtWVE0pyj3C-Xce-5_FgMSqLpP0g8AsE1ARjOwesDt8z6mfwq"); | |
} | |
function myFriends(){ | |
var friends = [ | |
{name: "erin", hair: "brown"}, | |
{name: "amanda", hair: "red"}, | |
{name: "andy", hair: "black"} | |
]; | |
for (var i = 0; i < friends.length; i++){ | |
describeFriend(friends[i]); | |
} | |
} | |
function describeFriend(friend){ | |
var message = "my friend is " + friend.name + ", whose hair color is " + friend.hair + "."; | |
alert(message); | |
} | |
function favoriteThings(){ | |
var myFavoriteThings = ["javascript", "video games", "powerlifting"]; | |
var message = "My favorite things are "; | |
for (var i = 0; i < myFavoriteThings.length; i++){ | |
message = message + myFavoriteThings[i] + ", "; | |
} | |
alert(message); | |
} | |
function calculate(){ | |
var myAge = 27; | |
var maxAge = 100; | |
var coffeePerDay = 2; | |
var lifetimeSupply = (maxAge - myAge) * coffeePerDay * 365; | |
if (lifetimeSupply > 40000){ | |
document.body | |
//alert("you drink too much coffee"); | |
} else { | |
alert("you'll probably be fine"); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment