diff --git a/exercises.js b/exercises.js index 4ffe65f..7712cb3 100644 --- a/exercises.js +++ b/exercises.js @@ -11,11 +11,23 @@ const album1 = { } } -// 1. Retrieve the string "Sire" from album1, and save it in a sensibly named -// variable. +// album1.albumDetails.label +console.log(album1.albumDetails.label) +// dot notation to get value. In class +let labelName = album.albumDetails.label // 2. Change the title of album1 from "Talking Heads" to "Talking Heads: 77" + +//LEARN HOW TO GOOGLE PROPERLY, JEEEZE! Need key not value +// const obj = { oldKey: 'Talking Heads' }; +// obj.'Talking Heads: 77' = obj.'Talking Heads'; +// delete obj."Talking Heads"; +// console.log(obj); + +//class work +album1.title = "Talking Heads: 77" + const album2 = { title: "More Songs About Buildings and Food", albumDetails: { @@ -25,6 +37,7 @@ const album2 = { } } + const album3 = { title: "Fear of Music", albumDetails: { @@ -38,9 +51,13 @@ const album3 = { // album3's formats // Check out the Array.push method! +album3.albumDetails.formats.push("LP") + // 4. Change the release date of album3 from a string into a Date object // Look ahead to album4 for a clue! +//album3.albumDetails.released = new Date("August 3, 1979") + const album4 = { title: "Remain in Light", albumDetails: { @@ -60,6 +77,8 @@ const album5 = { } // 6. Add a 'formats' array to album 5 and add "CD", "Cassette", and "LP" +album5.albumDetails.formats = ("CD, "Cassette", "LP") + const album6 = { title: "Little Creatures", @@ -69,9 +88,13 @@ const album6 = { formats: ["CD", "cassette", "LP"] } } - +// album6.albumDetails.labels[1].toUpperCase() +// or to mutate + // 7. Make the label "emi" in album6 all uppercase // google how to make a string uppercase in js! +// .toLocaleUpperCase +// string.toUpperCase() const album7 = { title: "True Stories", @@ -81,11 +104,13 @@ const album7 = { formats: ["CD", "cassette", "LP"] } } - +let album7Split = album7.albumDetails.labels.split(", ") +album7.albumDetails.labels = album7Split // 8. Convert album7's 'labels' property from the string value // "Sire, EMI" into the array: ["Sire", "EMI"] // google js array split! + ///////////////////////////////////////////////////// // Part 2: More Tasks About Datatypes and Structures ///////////////////////////////////////////////////// @@ -111,18 +136,22 @@ const talkingHeadsAlbums = [ ] // 1. Create an object literal called `band`. +let band = { +} // 2. Give it the property `name` and set it to "Talking Heads" - +band.name = "Talking Heads" // 3. Give it the property `members` and set it to an array with a single -// string, "David Byrne", in it. +// string, "David Byrne", in it. +band.members = ["David Byrne"] // 4. Give it the property `albums` and set it to the array stored in the +band.albums = talkingHeadsAlbums // variable talkingHeadsAlbums // 5. Add "Tiny Weymouth", "Chris Franz" and "Jerry Harrison" to the members // array. - +band.members = ["David Byrne", "Tiny Weymouth", "Chris Franz", "Jerry Harrison"] //////////////////////////////////////////////// // Part 3: Conditional Logic //////////////////////////////////////////////// @@ -130,13 +159,24 @@ const talkingHeadsAlbums = [ // 1. Write a conditional to console.log "Talking Heads were a prolific band" // if the Talking Heads have 6 albums or more. Otherwise, console.log // "Talking heads didn't have much output." Use the array of albums -// talkingHeadsAlbums above. +// talkingHeadsAlbums above. + +if(albumsLength >= 6 ) { + console.log("Talking heads were a prolific band") +} else { +console.log ("Talking heads didn't have much out put") +} +) // 2. Write a conditional to check if the number of albums in // talkingHeadsAlbums is odd or even, and then console.log // "The number X is odd" or "The number X is even" with X being // the number of albums. - +if( (albumsLength.length % 2) === 0) { + console.log(`the number ${albumsLength} is even`) +} else { + console.log(`the number ${albumsLength} is odd`) +} // 3. Write conditionals to check if the number of albums in // talkingHeadsAlbums is divisible by either 2 or 3, and then // console.log one of: @@ -147,18 +187,45 @@ const talkingHeadsAlbums = [ // // with Y being the number of albums. +if((albumsLength % 3 === 0) && (albumsLength % 2 === 0)) { + console.log(`The number ${albumsLength} is divisible by 2 and 3`) +} else if (albumsLength % 2 === 0) { + console.log(`The number ${albumsLength} is divisible by 2`){ + } else if () +} + +} + // 4. Check your logic above against the numbers: 0, 1, 2, 6, 7, and 9. // Make sure it always works! +let testNumber = 0 ///////////////////////////////////////////////////// // Part 4: For Loops ///////////////////////////////////////////////////// // 1. Use a for loop to print out the name of each Talking Heads album - +for(album in talkingHeadsAlbums) { + console.log(talkingHeadsAlbums[album].title) +} // 2. Create a variable called `sireTally`, and set it to the integer value 0. + // Then use a for-loop to go through all the Talking Heads albums, // incrementing sireTally if the album was released under the "Sire" label. // // Warning: some albums have a property `.label`, which is a string, and some // have `.labels`, which is an Array! + +let sireTally = 0 + +for(album in talkingHeadsAlbums) { + if(talkingHeadsAlbums[album].albumDetails.label){ + if (talkingHeadsAlbums[album].albumDetails.label === "Sire") { + sireTally++ + } + } else if (talkingHeadsAlbums[album].albumDetails.labels){ + if (talkingHeadsAlbums[album].albumDetails.labels.include === "Sire") { + sireTally++ +} + } +} \ No newline at end of file