-
-
Save lstude/9105085 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
/* | |
* superBowlLineup Object | |
*/ | |
var superBowlLineup = { | |
date: "1/27/2014", | |
fireworksUsed: 534, | |
lightShow: true, | |
bands: [ | |
{ | |
"name": "Bruno Mars", | |
"songs": 5 | |
} | |
] | |
}; | |
console.log("superBowlLineup Object:", superBowlLineup); | |
console.log("superBowlLineup Date:", superBowlLineup.date); | |
console.log("superBowlLineup lightShow:", superBowlLineup.lightShow); | |
/* | |
* Add the function 'addBand' to the superBowlLineup object | |
*/ | |
superBowlLineup.addBand = function (band) { | |
superBowlLineup.bands.push(band); | |
}; | |
/* | |
* Define the Red Hot Chili Peppers | |
*/ | |
var rhcp = { | |
"name": "Red Hot Chili Peppers", | |
"songs": 5, | |
"members": { | |
"singer": "Anthony Kiedis", | |
"drummer": "Chad Smith", | |
"bassist": "Flea", | |
"guitarist": "Josh Klinghoffer" | |
} | |
}; | |
console.log("rchp object", rhcp); | |
/* | |
* Add the Red Hot Chili Peppers to the lineup | |
*/ | |
superBowlLineup.addBand(rhcp); | |
console.log("Lineup Length After Adding rhcp:", superBowlLineup.bands.length); | |
console.log("Band added name:", superBowlLineup.bands[1].name); | |
/* | |
* Add the ability to change the song number on a band in the superBowlLineup object. | |
* It should take 2 parameters, band name and number you want to change | |
*/ | |
superBowlLineup.changeAmountofSongs = function (band_name, song_number) { | |
// Use a for loop to go through each array to find the band_name | |
for (var i = 0; i < superBowlLineup.bands.length; i++) { | |
// If the band name is equal to the band_name passed | |
if (superBowlLineup.bands[i].name === band_name) { | |
// Change the song number on this specific array element to song_number | |
superBowlLineup.bands[i].songs = song_number; | |
} | |
} | |
}; | |
/* | |
* Change Chili Peppers song amount to 1. | |
*/ | |
superBowlLineup.changeAmountofSongs('Red Hot Chili Peppers', 1); | |
console.log(superBowlLineup.bands[1].name + " Song Amount:", superBowlLineup.bands[1].songs); | |
/* | |
* Create the table to show the lineup and amount of songs played | |
*/ | |
// Create the initial table string with the header Band and Song Number. | |
// To see how tables work, Google "HTML tables" | |
var table = "<table><thead><tr><td>Band</td><td>Song Number</td></tr></thead><tbody>"; | |
// Iterate through the object to with a for loop to add each row | |
for (var x = 0; x < superBowlLineup.bands.length; x+=1) { | |
table += "<tr>"; | |
table += "<td>" + superBowlLineup.bands[x].name + "</td>"; | |
table += "<td>" + superBowlLineup.bands[x].songs + "</td>"; | |
table += "</tr>"; | |
} | |
// Close the table | |
table = table + '</tbody></table>'; | |
// Use jQuery to select the body tag on the index and append the finish table string | |
$("body").append(table); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment