From 9403df24a88cd2d369cc7ed18b46056b1c9914ae Mon Sep 17 00:00:00 2001 From: username Date: Mon, 13 Mar 2023 16:22:28 -0700 Subject: [PATCH] was unable to get the bonus, will wait for class to review to understand what is going on --- bonus.js | 15 ++++++++++ exercises.js | 84 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 99 insertions(+) diff --git a/bonus.js b/bonus.js index bf067c4..78416a5 100644 --- a/bonus.js +++ b/bonus.js @@ -41,6 +41,7 @@ const ticketSections = [ {name: "Bob Dole", section: "center", type: "premium", seats: 3} ] + // 2. There is a concert at the LA County Fairgrounds by the Southland's // hottest Talking Heads tribute band for zombie afficianados, // "The Wailing Deads" (known as "The Walking Deads" until they received @@ -80,3 +81,17 @@ const tickets = [ {amount: 90.00}, {amount: 50.00, discount: true} ] + +const tickets = [ + {amount: 50.00, discount: false, zombie: true}, // STANDARD $10 DRINKS + {amount: 60.00, discount: true, zombie: false}, // INVALID + {amount: 50.00}, // STANDARD + {amount: 65.00, discount: true, zombie: true}, // PREMIER $20 DRINKS + {amount: 90.00, discount: false}, // PREMIER PLUS + {amount: 50.00, discount: true, zombie: false}, // STANDARD $10 DRINKS + {amount: 50.00, zombie: true}, // STANDARD $10 DRINKS + {amount: 80.00, discount: true}, // PREMIER PLUS + {amount: 90.00}, // PREMIER PLUS + {amount: 50.00, discount: true} // STANDARD $10 DRINKS +] + diff --git a/exercises.js b/exercises.js index 4ffe65f..3229703 100644 --- a/exercises.js +++ b/exercises.js @@ -14,7 +14,12 @@ const album1 = { // 1. Retrieve the string "Sire" from album1, and save it in a sensibly named // variable. +const label = album1.albumDetails.label + +const label = album1.albumDetails.label + // 2. Change the title of album1 from "Talking Heads" to "Talking Heads: 77" +album1.title = "Talking Heads: 77" const album2 = { title: "More Songs About Buildings and Food", @@ -38,9 +43,15 @@ const album3 = { // album3's formats // Check out the Array.push method! +album3.albumDetails.formats.push(album2.albumDetails.formats[0]) + + + // 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: { @@ -50,6 +61,7 @@ const album4 = { } // 5. Add the label "Sire" to album4's details +album4.albumDetails.label = "Sire" const album5 = { title: "Speaking in Tongues", @@ -60,6 +72,7 @@ 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", @@ -72,6 +85,9 @@ const album6 = { // 7. Make the label "emi" in album6 all uppercase // google how to make a string uppercase in js! +album6.albumDetails.labels[1] = album6.albumDetails.labels[1].toUpperCase() + + const album7 = { title: "True Stories", @@ -85,6 +101,8 @@ const album7 = { // 8. Convert album7's 'labels' property from the string value // "Sire, EMI" into the array: ["Sire", "EMI"] // google js array split! +album7.albumDetails.labels = album7.albumDetails.labels.split(",") + ///////////////////////////////////////////////////// // Part 2: More Tasks About Datatypes and Structures @@ -112,16 +130,29 @@ 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. +band.members = ["David Byrne"] + // 4. Give it the property `albums` and set it to the array stored in the // variable talkingHeadsAlbums +band.albums = talkingHeadsAlbums + // 5. Add "Tiny Weymouth", "Chris Franz" and "Jerry Harrison" to the members // array. +band.members.push("Tiny WeyMouth") +band.members.push("Chris Franz") +band.members.push("Jerry Harrison") //////////////////////////////////////////////// // Part 3: Conditional Logic @@ -132,10 +163,31 @@ const talkingHeadsAlbums = [ // "Talking heads didn't have much output." Use the array of albums // talkingHeadsAlbums above. +if(talkingHeadsAlbums.length >= 6) { + console.log("Talking Heads were a prolific band") +} else { + console.log("Talking heads didn't have much output.") +} + + + + + // 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. +var numOfAlbums = talkingHeadsAlbums.length +if(numOfAlbums % 2 === 0) { + console.log("The number", numOfAlbums, "is even") +} else { + console.log("The number", numOfAlbums, "is odd") +} + + + + + // 3. Write conditionals to check if the number of albums in // talkingHeadsAlbums is divisible by either 2 or 3, and then @@ -147,6 +199,20 @@ const talkingHeadsAlbums = [ // // with Y being the number of albums. +var numAlbums = talkingHeadsAlbums.length + +if(numAlbums === 0) { + console.log("The number 0 is not divisible by 2 or 3 ") +} else if(numAlbums % 2 === 0 && numAlbums % 3 === 0) { + console.log(`The number ${numAlbums} is divisible by 2 and 3`) +} else if(numAlbums % 3 === 0) { + console.log(`The number ${numAlbums} is divisible by 3`) +} else if(numAlbums % 2 === 0) { + console.log(`The number ${numAlbums} is divisible by 2`) +} else { + console.log(`The number ${numAlbums} is not divisible by 2 or 3`) +} + // 4. Check your logic above against the numbers: 0, 1, 2, 6, 7, and 9. // Make sure it always works! @@ -155,6 +221,11 @@ const talkingHeadsAlbums = [ ///////////////////////////////////////////////////// // 1. Use a for loop to print out the name of each Talking Heads album +for(album of talkingHeadsAlbums) { + console.log(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, @@ -162,3 +233,16 @@ const talkingHeadsAlbums = [ // // Warning: some albums have a property `.label`, which is a string, and some // have `.labels`, which is an Array! +let sireTally = 0 +for(album of talkingHeadsAlbums) { + // If the property name is "label" + if(album.albumDetails.label === "Sire") { + sireTally++ + } + // If the property name is "labels" + if(album.albumDetails.labels) { + if(album.albumDetails.labels.includes("Sire")) { + sireTally++ + } + } +} \ No newline at end of file