Created
April 13, 2016 22:00
-
-
Save JoeShep/9d265f45eb83e5634ff205d2f48b0e1d to your computer and use it in GitHub Desktop.
Objects 101
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
All the values in these objects happen to be strings ("Carly Rae Jepsen", "Livin on a Prayer", etc), but values can be any data type: | |
String, array, boolean, null, undefined, even other objects. |
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
var annoyingSongs = []; | |
var callMeMaybe = { | |
//this is the "key" //This is the "value" | |
title: "Call Me Maybe", // <---object properties are separated by commas | |
artist: "Carly Rae Jepsen", | |
album: "Curiosity" | |
}; | |
annoyingSongs.push(callMeMaybe); | |
var prayer = { | |
title: "Livin on a Prayer", | |
artist: "Bon Jovi", | |
album: "Slippery When Wet" | |
}; | |
annoyingSongs.push(prayer); | |
var hampster = { | |
title: "The Hampsterdance Song", | |
artist: "Hampton the Hampster", | |
album: "The Hampsterdance Album" | |
}; | |
annoyingSongs.push(hampster); | |
var gangnamStyle = { | |
title: "Gangnam Style", | |
artist: "Psy", | |
album: "Psy 6" | |
}; | |
annoyingSongs.push(gangnamStyle); | |
console.log("annoyingSongs", annoyingSongs); | |
var songElements = document.getElementsByClassName("songs"); | |
console.log("songElements",songElements); | |
var theOneImLookingFor = songElements[0]; | |
console.log("theOneImLookingFor",theOneImLookingFor); | |
for (var i = 0; i < annoyingSongs.length; i++) { | |
var currentSong = annoyingSongs[i]; | |
var title = "<h2>" + currentSong.title + "</h2>"; | |
var album = "<h3>" + currentSong.album + "</h3>"; | |
theOneImLookingFor.innerHTML += "<h1>The most annoying songs ever: # " + (i+1) + "</h1>" + title + album; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment