diff --git a/airport/airport-test.js b/airport/airport-test.js index 246224309..cf3a3ecee 100644 --- a/airport/airport-test.js +++ b/airport/airport-test.js @@ -2,7 +2,7 @@ var assert = require('chai').assert; var { createAirport, welcomeGuests, landPlanes, checkAirlineLocations } = require('./airport'); describe('Airport', function() { - it.skip('should create an airport', function() { + it('should create an airport', function() { var airport = createAirport('Denver International Airport', ['United', 'Southwest', 'Delta'], 144); assert.equal(airport.name, 'Denver International Airport'); @@ -10,7 +10,7 @@ describe('Airport', function() { assert.equal(airport.airlines[0], 'United'); }); - it.skip('should welcome people to the airport', function() { + it('should welcome people to the airport', function() { var denverAirport = createAirport('Denver International Airport', ['United', 'Southwest', 'Delta'], 144); var sanDiegoAirport = createAirport('San Diego International Airport', ['Frontier', 'American'], 48); @@ -22,7 +22,7 @@ describe('Airport', function() { assert.equal(sanDiegoWelcome, 'Welcome to San Diego International Airport!'); }); - it.skip('should keep track of open gates', function() { + it('should keep track of open gates', function() { var bakersfieldAirport = createAirport('Meadows Field Airport', ['United', 'American'], 12); var sanDiegoAirport = createAirport('San Diego International Airport', ['Frontier', 'American'], 48); @@ -33,7 +33,7 @@ describe('Airport', function() { assert.equal(sanDiegoAirport.availableGates, 46); }); - it.skip('should not be able to occupy more gates than available', function() { + it('should not be able to occupy more gates than available', function() { var columbusAiport = createAirport('John Glenn Airport', ['Southwest', 'Frontier'], 24); var occupiedGates1 = landPlanes(columbusAiport, 22); @@ -47,7 +47,7 @@ describe('Airport', function() { assert.equal(occupiedGates2, 'Oh no! Not enough gates available. Current overflow is 1.') }); - it.skip('should be able to tell you where an airline flies to', function() { + it('should be able to tell you where an airline flies to', function() { var columbusAiport = createAirport('John Glenn Airport', ['Southwest', 'Frontier'], 24); var bakersfieldAirport = createAirport('Meadows Field Airport', ['United', 'American'], 12); var sanDiegoAirport = createAirport('San Diego International Airport', ['Frontier', 'American'], 48); diff --git a/airport/airport.js b/airport/airport.js index 8966a87f7..28ee06394 100644 --- a/airport/airport.js +++ b/airport/airport.js @@ -2,8 +2,45 @@ module.exports = { - // createAirport, - // welcomeGuests, - // landPlanes, - // checkAirlineLocations + createAirport, + welcomeGuests, + landPlanes, + checkAirlineLocations }; + +function createAirport(location, airlines, gates) { + var airport = { + name: location, + availableGates: gates, + airlines: airlines + } + return airport; +} + +function welcomeGuests(airport) { + return `Welcome to ${airport.name}!` +} + +function landPlanes(airport, planes) { + airport.availableGates = airport.availableGates - planes; + if (airport.availableGates > 0) { + return `Success! Current availability is ${airport.availableGates}.`; + } + if (airport.availableGates <= 0) { + var overflow = airport.availableGates * -1; + airport.availableGates = 0; + return `Oh no! Not enough gates available. Current overflow is ${overflow}.` + } +} + +function checkAirlineLocations(airports, airline) { + var carriers = []; + for (var i = 0; i < airports.length; i++) { + for (var j = 0; j < airports[i].airlines.length; j++) { + if (airline === airports[i].airlines[j]) { + carriers.push(airports[i].name) + } + } + } + return carriers; +} \ No newline at end of file diff --git a/barber-shop/barber-test.js b/barber-shop/barber-test.js index 9f589ff64..e93449116 100644 --- a/barber-shop/barber-test.js +++ b/barber-shop/barber-test.js @@ -2,13 +2,13 @@ var assert = require('chai').assert; var { createBarber, giveCompliment, cutHair, listStyles } = require('./barber'); describe('Barber', function() { - it.skip('should create a barber with a name', function() { + it('should create a barber with a name', function() { var sam = createBarber('Sam'); assert.equal(sam.name, 'Sam'); }) - it.skip('should be able to have earnings and known haircuts', function() { + it('should be able to have earnings and known haircuts', function() { var cut1 = { style: 'mohawk', hairLength: 'short', price: 11.00 }; var cut2 = { style: 'side part', hairLength: 'medium', price: 12.00 }; @@ -19,7 +19,7 @@ describe('Barber', function() { assert.deepEqual(erin.haircuts, [cut1, cut2]); }); - it.skip('should default to no earnings and no haircuts if none provided', function() { + it('should default to no earnings and no haircuts if none provided', function() { var buzzCut = { style: 'buzz', hairLength: 'short', price: 8.00 }; var nick = createBarber('Nick', 8.00, [buzzCut]); @@ -32,7 +32,7 @@ describe('Barber', function() { assert.deepEqual(pam.haircuts, []); }); - it.skip('should be able to offer a compliment', function() { + it('should be able to offer a compliment', function() { var mohawkCut = { style: 'mohawk', hairLength: 'short', price: 11.00 }; var buzzCut = { style: 'buzz', hairLength: 'short', price: 8.00 }; @@ -45,7 +45,7 @@ describe('Barber', function() { assert.equal(buzzCompliment, 'This buzz looks great!'); }); - it.skip('should be able to cut hair', function() { + it('should be able to cut hair', function() { var matt = createBarber('Matt'); var mohawkCut = { style: 'mohawk', hairLength: 'short', price: 11.00 }; @@ -64,7 +64,7 @@ describe('Barber', function() { assert.deepEqual(mattCanDoMohawkAndBuzz.haircuts, [ mohawkCut, buzzCut ]); }); - it.skip('should earn money for hair cuts', function() { + it('should earn money for hair cuts', function() { var erin = createBarber('Erin'); var buzzCut = { style: 'buzz', hairLength: 'short', price: 8.00 }; @@ -79,7 +79,7 @@ describe('Barber', function() { assert.equal(erinCanDoBuzzAndSidePart.earnings, 18.00); }); - it.skip('should be able to list style options based on desired length', function() { + it('should be able to list style options based on desired length', function() { var buzzCut = { style: 'buzz', hairLength: 'short', price: 8.00 }; var sidePartCut = { style: 'side part', hairLength: 'medium', price: 10.00 }; var bobCut = { style: 'bob', hairLength: 'short', price: 12.00 }; diff --git a/barber-shop/barber.js b/barber-shop/barber.js index 16d2dd549..8580767c9 100644 --- a/barber-shop/barber.js +++ b/barber-shop/barber.js @@ -1,3 +1,53 @@ -module.exports = { }; \ No newline at end of file +module.exports = { + createBarber, + giveCompliment, + cutHair, + listStyles +}; + +function createBarber(name, earnings, cuts) { + var barber = { + name: name, + earnings: earnings, + haircuts: cuts + } + if (earnings === undefined) { + barber.earnings = 0; + } + if (cuts === undefined) { + barber.haircuts = []; + } + return barber; +} + +function giveCompliment(cut) { + return `This ${cut.style} looks great!`; +} + +function cutHair(barber, haircut) { + // take haircut and push it into haircuts array + var counter = 0; + barber.haircuts.push(haircut); + for (var i = 0; i < barber.haircuts.length; i++) { + counter = counter + barber.haircuts[i].price; + } + barber.earnings = counter; + return barber; +} + +// should earn money for haircuts +// create a for loop that iterates through the haircuts array in the barber object + // add each of the numbers under price and add them to empty counter variable + // push counter into earnings. + +function listStyles(barber, haircutLength) { + var styles = []; + for (var i = 0; i < barber.haircuts.length; i++) { + if (barber.haircuts[i].hairLength === haircutLength) { + styles.push(barber.haircuts[i].style) + } + } + return styles; +} \ No newline at end of file diff --git a/birthdays/birthdays-test.js b/birthdays/birthdays-test.js index a2573d210..5b082c279 100644 --- a/birthdays/birthdays-test.js +++ b/birthdays/birthdays-test.js @@ -2,7 +2,7 @@ var assert = require('chai').assert; var { createBirthday, celebrateBirthday, countBirthdays } = require('./birthdays'); describe('Birthdays', function() { - it.skip('should create birthdays', function() { + it('should create birthdays', function() { var leahBirthday = createBirthday('Leah', 2, 10); var christyBirthday = createBirthday('Christy', 3, 8); @@ -15,7 +15,7 @@ describe('Birthdays', function() { assert.deepEqual(christyBirthday.day, 8); }); - it.skip('should celebrate birthdays', function() { + it('should celebrate birthdays', function() { var alexBirthday = createBirthday('Alex', 5, 19); var celebrateAlex = celebrateBirthday(alexBirthday); @@ -29,7 +29,7 @@ describe('Birthdays', function() { assert.equal(celebrateHeather, 'Today is 6/29! Happy birthday, Heather!'); }) - it.skip('should count how many birthdays are in a given month', function() { + it('should count how many birthdays are in a given month', function() { var leahBirthday = createBirthday('Leah', 2, 10); var christyBirthday = createBirthday('Christy', 3, 8); var alexBirthday = createBirthday('Alex', 5, 19); diff --git a/birthdays/birthdays.js b/birthdays/birthdays.js index 16d2dd549..2b75e1004 100644 --- a/birthdays/birthdays.js +++ b/birthdays/birthdays.js @@ -1,3 +1,30 @@ +function createBirthday(name, month, day) { + var birthdays = { + name: name, + month: month, + day: day, + } + return birthdays; +} +function celebrateBirthday (birthday){ +var name = birthday.name +var month = birthday.month +var day = birthday.day +return `Today is ${month}/${day}! Happy birthday, ${name}!` +} -module.exports = { }; \ No newline at end of file +function countBirthdays(birthdays, month) { + birthdaysCounter = 0; + for (var i = 0; i < birthdays.length; i++) { + if (birthdays[i].month === month) { + birthdaysCounter++; + } + } + return birthdaysCounter; +} +module.exports = { + createBirthday, + celebrateBirthday, + countBirthdays + }; \ No newline at end of file diff --git a/calendar/calendar-test.js b/calendar/calendar-test.js index b6f554a08..1072025ab 100644 --- a/calendar/calendar-test.js +++ b/calendar/calendar-test.js @@ -3,7 +3,7 @@ var { createEvent, createCalendar, reportMonthlyEvents } = require('./calendar') describe('Calendar', function () { - it.skip('should create an event', function () { + it('should create an event', function () { var event = createEvent("Go to the Park", "August", 25); assert.equal(event.title, "Go to the Park"); @@ -18,7 +18,7 @@ describe('Calendar', function () { assert.equal(event2.day, 1); }); - it.skip('should return an error if an invalid day is passed in', function () { + it('should return an error if an invalid day is passed in', function () { var event1 = createEvent("Go to the Park", "August", 35); assert.equal(event1, "Error: 35 is not a valid day"); @@ -26,7 +26,7 @@ describe('Calendar', function () { assert.equal(event2, "Error: 0 is not a valid day"); }); - it.skip('should create a calendar with events', function () { + it('should create a calendar with events', function () { var event1 = createEvent("Go to the Park", "August", 25); var event2 = createEvent("Dinner with Lucy", "September", 10); var events = [event1, event2]; @@ -43,7 +43,7 @@ describe('Calendar', function () { assert.deepEqual(calendar2.events, [event1, event2]); }); - it.skip('should gather events from the same month', function () { + it('should gather events from the same month', function () { var event1 = createEvent("Go to the Park", "August", 25); var event2 = createEvent("Dinner with Lucy", "July", 10); var event3 = createEvent("Order More Batteries", "July", 2); diff --git a/calendar/calendar.js b/calendar/calendar.js index 16d2dd549..a6dd26077 100644 --- a/calendar/calendar.js +++ b/calendar/calendar.js @@ -1,3 +1,38 @@ -module.exports = { }; \ No newline at end of file +module.exports = { + createEvent, + createCalendar, + reportMonthlyEvents +}; + +function createEvent(title, month, day) { + if (day > 0 && day < 32) { + var event = { + title: title, + month: month, + day: day + } + return event; + } else { + return `Error: ${day} is not a valid day` + } +}; + +function createCalendar(name, events) { + var calendar = { + owner: name, + events: events + } + return calendar; +}; + +function reportMonthlyEvents(calendar, monthCheck) { + var monthEvent = []; + for (var i = 0; i < calendar.events.length; i++) { + if (calendar.events[i].month === monthCheck) { + monthEvent.push(calendar.events[i]) + } + } + return monthEvent; +}; \ No newline at end of file diff --git a/dj/dj-test.js b/dj/dj-test.js index 348244995..d5b670f8f 100644 --- a/dj/dj-test.js +++ b/dj/dj-test.js @@ -1,15 +1,15 @@ -var { createSong } = require('./dj'); +var { createSong, playSong, makePlaylist, addSongToPlaylist, playAllSongs } = require('./dj'); var assert = require('chai').assert; describe('dj', function() { - it.skip('should be able to create songs', function() { + it('should be able to create songs', function() { var song = createSong('Zombie Shuffle', 'The Creepy Crawlers') assert.equal(song.name, 'Zombie Shuffle'); assert.equal(song.artist, 'The Creepy Crawlers'); }) - it.skip('should not have been played by default', function() { + it('should not have been played by default', function() { var song = createSong('Witches\' Brew Boogie', 'The Ghostly Ghouls') assert.equal(song.name, 'Witches\' Brew Boogie'); @@ -18,19 +18,19 @@ describe('dj', function() { }) - it.skip('should be able to play a song', function() { + it('should be able to play a song', function() { var song = createSong('I Put A Spell On You', 'Bette Midler, Sarah Jessica Parker & Kathy Najimy', false) assert.equal(song.name, 'I Put A Spell On You'); assert.equal(song.artist, 'Bette Midler, Sarah Jessica Parker & Kathy Najimy'); assert.equal(song.hasBeenPlayed, false); - var playedSong = playSong(song) + var playedSong = playSong(song); assert.equal(playedSong.hasBeenPlayed, true); }) - it.skip('should be able to create a playlist', function() { + it('should be able to create a playlist', function() { var skeletonSong = createSong('Skeletons in the Closet Rock', 'The Skeletal Band', false); var tangoTrack = createSong('Trick or Treat Tango', 'The Spooky Cats', false); @@ -40,7 +40,7 @@ describe('dj', function() { assert.deepEqual(playlist.songs, [skeletonSong, tangoTrack]) }) - it.skip('should be able to add songs to a playlist', function() { + it('should be able to add songs to a playlist', function() { var jingleJive = createSong('Jingle Bell Jive', 'The Dancing Elves'); var holidayPlaylist = makePlaylist('Holiday Songs', [jingleJive]); @@ -55,7 +55,7 @@ describe('dj', function() { assert.deepEqual(updatedHolidayPlaylist.songs, [jingleJive, funkyFrosty]) }) - it.skip('should be able to play all the songs', function() { + it('should be able to play all the songs', function() { var rockinSong = createSong('Rockin\' Around the Christmas Treehouse', 'The Yuletide Youth'); var shuffleSong = createSong('Santa\'s Sleigh Ride Shuffle', 'The Jolly Jinglesters') var reggaeSong = createSong('Rudolph\'s Reggae Jam', 'The Reindeer Rhythms') diff --git a/dj/dj.js b/dj/dj.js index 4d63f6a76..8e8acc3a2 100644 --- a/dj/dj.js +++ b/dj/dj.js @@ -1,4 +1,47 @@ -module.exports = { }; +module.exports = { + createSong, + playSong, + makePlaylist, + addSongToPlaylist, + playAllSongs + }; + + function createSong(name, artist, played) { + var song = { + name: name, + artist: artist, + hasBeenPlayed: false + } + if (played !== undefined) { + song.hasBeenPlayed = played; + } + return song; + } + + function playSong(song) { + song.hasBeenPlayed = true; + return song; + } + + function makePlaylist(name, songs) { + var playlist = { + name: name, + songs: songs + } + return playlist; + } + + function addSongToPlaylist(playlist, song) { + playlist.songs.push(song); + return playlist; + } + + function playAllSongs(playlist) { + for (var i = 0; i < playlist.songs.length; i++) { + playlist.songs[i].hasBeenPlayed = true; + } + return playlist; + } \ No newline at end of file diff --git a/dollar-store-vending-machine/index-test.js b/dollar-store-vending-machine/index-test.js index 0891b1b88..563baf1c0 100644 --- a/dollar-store-vending-machine/index-test.js +++ b/dollar-store-vending-machine/index-test.js @@ -3,7 +3,7 @@ var { createItemStock, collectChange, makePurchase } = require('./index') describe('dollar store vending machine functions', function() { describe('createItemStock', function() { - it.skip('can collect the details of a stocked item', function() { + it('can collect the details of a stocked item', function() { const name = 'chips' const quantity = 10 const price = 1.25 @@ -18,7 +18,7 @@ describe('dollar store vending machine functions', function() { assert.deepEqual(itemStock, expectedResult) }) - it.skip('should return an item with defaults if nothing is passed', function() { + it('should return an item with defaults if nothing is passed', function() { const expectedResult = { name: 'unknown', quantity: 0, @@ -31,7 +31,7 @@ describe('dollar store vending machine functions', function() { }) describe('makePurchase', function() { - it.skip('does not allow a purchase if given less than price', function() { + it('does not allow a purchase if given less than price', function() { const selectedItem = createItemStock('chips', 2, 2.00) const moneyForPurchase = 0.35 const expectedResult = 'Sorry, you need at least $2 to make that purchase' @@ -41,7 +41,7 @@ describe('dollar store vending machine functions', function() { assert.equal(transactionResult, expectedResult) }) - it.skip('does not allow a purchase if given less than different price', function() { + it('does not allow a purchase if given less than different price', function() { const selectedItem = createItemStock('soda', 2, 1.00) const moneyForPurchase = 0.35 const expectedResult = 'Sorry, you need at least $1 to make that purchase' @@ -51,7 +51,7 @@ describe('dollar store vending machine functions', function() { assert.equal(transactionResult, expectedResult) }) - it.skip('does not allow a purchase if no items of that type are available', function() { + it('does not allow a purchase if no items of that type are available', function() { const selectedItem = createItemStock('chips', 0, 2.00) const moneyForPurchase = 2.00 const expectedResult = 'Sorry, there are none left' @@ -61,7 +61,7 @@ describe('dollar store vending machine functions', function() { assert.equal(transactionResult, expectedResult) }) - it.skip('allows the transaction if successful', function() { + it('allows the transaction if successful', function() { const selectedItem = createItemStock('chips', 1, 2.00) const moneyForPurchase = 2.00 const expectedResult = 'Here are your chips' @@ -73,7 +73,7 @@ describe('dollar store vending machine functions', function() { assert.deepEqual(transactionResult, expectedResult) }) - it.skip('allows a different transaction if successful', function() { + it('allows a different transaction if successful', function() { const selectedItem = createItemStock('skittles', 1, 1.00) const moneyForPurchase = 1.00 const expectedResult = 'Here are your skittles' @@ -87,7 +87,7 @@ describe('dollar store vending machine functions', function() { }) describe('collectChange', function() { - it.skip('can calculate the total of a single coin', function() { + it('can calculate the total of a single coin', function() { const looseChange = [0.25] const expectedTotal = 0.25 @@ -96,7 +96,7 @@ describe('dollar store vending machine functions', function() { assert.deepEqual(total, expectedTotal) }) - it.skip('can calculate the total of two coins', function() { + it('can calculate the total of two coins', function() { const looseChange = [0.25, 0.10] const expectedTotal = 0.35 @@ -105,7 +105,7 @@ describe('dollar store vending machine functions', function() { assert.deepEqual(total, expectedTotal) }) - it.skip('can calculate the total of many coins', function() { + it('can calculate the total of many coins', function() { const looseChange = [0.25, 0.10, 0.25, 0.05, 1.00] const expectedTotal = 1.65 diff --git a/dollar-store-vending-machine/index.js b/dollar-store-vending-machine/index.js index 5704bb728..592ecfcdd 100644 --- a/dollar-store-vending-machine/index.js +++ b/dollar-store-vending-machine/index.js @@ -1,2 +1,42 @@ -module.exports = {} +module.exports = { + createItemStock, + collectChange, + makePurchase +} + +function createItemStock(name, quantity, price) { + var item = { + name: name, + quantity: quantity, + price: price + } + if (!item.name) { + item.name = 'unknown'; + } + if (!item.quantity) { + item.quantity = 0; + } + if (!item.price) { + item.price = 1.00; + } + return item; +} + +function makePurchase(item, money) { + if (money < item.price) { + return "Sorry, you need at least $" + item.price + " to make that purchase" + } + if (!item.quantity) { + return "Sorry, there are none left" + } + return `Here are your ${item.name}` +} + +function collectChange(change) { + var counter = 0; + for (var i = 0; i < change.length; i++) { + counter = counter + change[i]; + } + return counter; +} \ No newline at end of file diff --git a/elevator/elevator-test.js b/elevator/elevator-test.js index 414b4abe0..855a40825 100644 --- a/elevator/elevator-test.js +++ b/elevator/elevator-test.js @@ -2,7 +2,7 @@ var assert = require('chai').assert; var { createElevator, changeFloors, dropOffPassenger } = require('./elevator'); describe('Elevator', function() { - it.skip('should create an elevator', function() { + it('should create an elevator', function() { var elevator = createElevator('Empire State Building', 102, 5, ['Stacey', 'Javier', 'Tom']); assert.equal(elevator.building, 'Empire State Building'); @@ -11,7 +11,7 @@ describe('Elevator', function() { assert.deepEqual(elevator.passengers, ['Stacey', 'Javier', 'Tom']); }); - it.skip('should be able to change floors', function() { + it('should be able to change floors', function() { var elevator = createElevator('Empire State Building', 102, 5, []); var message = changeFloors(elevator, 10); @@ -19,7 +19,7 @@ describe('Elevator', function() { assert.equal(message, 'Taking you to floor 10!'); }); - it.skip('should not be able to change floors if already on that floor', function() { + it('should not be able to change floors if already on that floor', function() { var elevator = createElevator('West High School', 3, 2, ['Sarah', 'Ari']); var message = changeFloors(elevator, 2); @@ -27,7 +27,7 @@ describe('Elevator', function() { assert.equal(message, 'You\'re already on floor 2!'); }); - it.skip('should not be able to take you to a floor that does not exist', function() { + it('should not be able to take you to a floor that does not exist', function() { var elevator = createElevator('West High School', 3, 2, ['Katherine', 'Erika']); var message = changeFloors(elevator, 100); @@ -35,7 +35,7 @@ describe('Elevator', function() { assert.equal(message, 'Floor 100 does not exist!'); }); - it.skip('should be able to drop off passenger', function() { + it('should be able to drop off passenger', function() { var elevator = createElevator('Upper Valley Mall', 4, 1, ['Scott', 'Mark', 'Joey']); var remainingPassengers = dropOffPassenger(elevator, 'Mark'); diff --git a/elevator/elevator.js b/elevator/elevator.js index 8740d66ab..0477c2987 100644 --- a/elevator/elevator.js +++ b/elevator/elevator.js @@ -1,3 +1,37 @@ -module.exports = { }; +module.exports = { + createElevator, + changeFloors, + dropOffPassenger + }; + + function createElevator(building, floors, currentFloor, passengers) { + var elevator = { + building: building, + floors: floors, + currentFloor: currentFloor, + passengers: passengers + } + return elevator; + } + + function changeFloors(elevator, floor) { + if (elevator.currentFloor === floor) { + return `You're already on floor ${floor}!` + } + if (floor > elevator.floors) { + return `Floor ${floor} does not exist!` + } + elevator.currentFloor = floor; + return `Taking you to floor ${floor}!`; + }; + + function dropOffPassenger(elevator, passenger) { + for (var i = 0; i < elevator.passengers.length; i++) { + if (elevator.passengers[i] === passenger) { + elevator.passengers.splice(i, 1); + } + } + return elevator.passengers; + } \ No newline at end of file diff --git a/favorite-foods/favorite-foods-test.js b/favorite-foods/favorite-foods-test.js index bc5f7985b..472df8929 100644 --- a/favorite-foods/favorite-foods-test.js +++ b/favorite-foods/favorite-foods-test.js @@ -1,27 +1,27 @@ -var { createFavoriteFood } = require('./favorite-foods'); +var { createFavoriteFood, commentOnSpiciness, orderFood, createShoppingList } = require('./favorite-foods'); var assert = require('chai').assert; describe('favorite foods', function () { - it.skip('should create a new dish with a name', function () { + it('should create a new dish with a name', function () { var pizza = createFavoriteFood({ dish: 'Pizza' }); assert.equal(pizza.name, 'Pizza'); }); - it.skip('should be able to create a different dish', function () { + it('should be able to create a different dish', function () { var smoothie = createFavoriteFood({ dish: 'Smoothie' }); assert.equal(smoothie.name, 'Smoothie'); }); - it.skip('should have ingredients', function () { + it('should have ingredients', function () { var tacos = createFavoriteFood({ dish: 'Tacos', ingredients: ['Tortilla', 'Ground Beef', 'Lettuce', 'Tomatoes', 'Sour Cream', 'Salsa'] }); assert.equal(tacos.name, 'Tacos'); assert.deepEqual(tacos.ingredients, ['Tortilla', 'Ground Beef', 'Lettuce', 'Tomatoes', 'Sour Cream', 'Salsa']); }); - it.skip('should be able to have different ingredients', function () { + it('should be able to have different ingredients', function () { var burger = createFavoriteFood({ dish: 'Burger', ingredients: ['Bun', 'Beef Patty', 'Lettuce', 'Tomato', 'Cheese', 'Ketchup', 'Mustard'] }); var sushi = createFavoriteFood({ dish: 'Sushi', ingredients: ['Rice', 'Salmon', 'Tuna', 'Avocado', 'Cucumber', 'Soy Sauce', 'Wasabi'] }); @@ -32,7 +32,7 @@ describe('favorite foods', function () { assert.deepEqual(sushi.ingredients, ['Rice', 'Salmon', 'Tuna', 'Avocado', 'Cucumber', 'Soy Sauce', 'Wasabi']); }); - it.skip('should be spicy or not', function () { + it('should be spicy or not', function () { var pancakes = createFavoriteFood({ dish: 'Pancakes', ingredients: ['Flour', 'Egg', 'Milk', 'Butter', 'Maple Syrup'], isSpicy: false }); var padThai = createFavoriteFood({ dish: 'Pad Thai', ingredients: ['Rice Noodles', 'Shrimp', 'Tofu', 'Egg', 'Bean Sprouts', 'Peanuts', 'Lime'], isSpicy: true }); @@ -45,7 +45,7 @@ describe('favorite foods', function () { assert.equal(padThai.isSpicy, true); }); - it.skip('should be able to taste the food and comment on how spicy it is', function () { + it('should be able to taste the food and comment on how spicy it is', function () { var dish1 = createFavoriteFood({ dish: 'Pho', ingredients: ['Rice Noodles', 'Beef', 'Bean Sprouts', 'Basil', 'Lime', 'Sriracha'], isSpicy: true }); var dish2 = createFavoriteFood({ dish: 'Lasagna', ingredients: ['Lasagna Noodles', 'Ground Beef', 'Tomato Sauce', 'Ricotta Cheese', 'Mozzarella Cheese'], isSpicy: false }); @@ -56,13 +56,13 @@ describe('favorite foods', function () { assert.equal(comment2, 'Phew, this Lasagna is not very spicy.'); }); - it.skip('should start off having ordered 0 times', function () { + it('should start off having ordered 0 times', function () { var dish = createFavoriteFood('Falafel', ['Chickpeas', 'Garlic', 'Onion', 'Cumin', 'Tahini', 'Pita Bread'], true); assert.equal(dish.timesOrdered, 0); }); - it.skip('should be able to order dishes', function () { + it('should be able to order dishes', function () { var dish1 = createFavoriteFood({ dish: 'Fish and Chips', ingredients: ['Fish Fillet', 'Potatoes', 'Flour', 'Egg', 'Beer', 'Tartar Sauce'], isSpicy: false }); var dish2 = createFavoriteFood({ dish: 'Chicken Curry', ingredients: ['Chicken', 'Coconut Milk', 'Onion', 'Garlic', 'Rice'], isSpicy: true }); var dish3 = createFavoriteFood({ dish: 'Ice Cream', ingredients: ['Milk', 'Cream', 'Sugar', 'Vanilla Extract', 'Chocolate Chips'], isSpicy: false }); @@ -81,7 +81,7 @@ describe('favorite foods', function () { }) // spicy 🌶️ - it.skip('should be able to make a list of all ingredients needed for multiple dishes', function () { + it('should be able to make a list of all ingredients needed for multiple dishes', function () { var pizza = createFavoriteFood({ dish: 'Pizza', ingredients: ['Tomato Sauce', 'Cheese', 'Pepperoni', 'Mushrooms'], isSpicy: false }); var smoothie = createFavoriteFood({ dish: 'Smoothie', ingredients: ['Banana', 'Strawberry', 'Blueberry', 'Milk', 'Honey'], isSpicy: false }) diff --git a/favorite-foods/favorite-foods.js b/favorite-foods/favorite-foods.js index 5f93c3872..71cbc6e87 100644 --- a/favorite-foods/favorite-foods.js +++ b/favorite-foods/favorite-foods.js @@ -1,4 +1,41 @@ -module.exports = { }; \ No newline at end of file +module.exports = { + createFavoriteFood, + commentOnSpiciness, + orderFood, + createShoppingList + }; + + function createFavoriteFood(dish) { + var favoriteFood = { + name: dish.dish, + ingredients: dish.ingredients, + isSpicy: dish.isSpicy, + timesOrdered: 0 + } + return favoriteFood; + } + + function commentOnSpiciness(dish) { + if (dish.isSpicy) { + return `Wow, this ${dish.name} is so spicy!` + } + return `Phew, this ${dish.name} is not very spicy.` + } + +function orderFood(dish) { + dish.timesOrdered++; + return dish; +} + +function createShoppingList(dishes) { + var list = []; + for (var i = 0; i < dishes.length; i++) { + for (var j = 0; j < dishes[i].ingredients.length; j++) { + list.push(dishes[i].ingredients[j]); + } + } + return list; +} \ No newline at end of file diff --git a/library/library-test.js b/library/library-test.js index 998130592..36e03da80 100644 --- a/library/library-test.js +++ b/library/library-test.js @@ -3,7 +3,7 @@ var assert = require('chai').assert; describe('Library', function() { - it.skip('should issue a library card', function() { + it('should issue a library card', function() { var card = issueCard('George', 32); assert.equal(card.name, 'George'); @@ -11,7 +11,7 @@ describe('Library', function() { assert.equal(card.numBooksCheckedOut, 0); }); - it.skip('should issue a card and check if it belongs to a child younger than 12 years old', function() { + it('should issue a card and check if it belongs to a child younger than 12 years old', function() { var card = issueCard('George', 32); assert.equal(card.name, 'George'); @@ -27,7 +27,7 @@ describe('Library', function() { assert.equal(childCard.isChild, true); }); - it.skip('should be able to search through a catalog by author and return book result', function() { + it('should be able to search through a catalog by author and return book result', function() { var collection = [ {title: 'My Life', author: 'Alex', status: 'on shelf'}, {title: 'Adventures', author: 'Sam', status: 'checked out'}, @@ -39,7 +39,7 @@ describe('Library', function() { assert.deepEqual(searchResults, [{title: 'Adventures', author: 'Sam', status: 'checked out'}]); }); - it.skip('should be able to handle a search with multiple results', function() { + it('should be able to handle a search with multiple results', function() { var collection = [ {title: 'My Life', author: 'Alex', status: 'on shelf'}, {title: 'Adventures', author: 'Sam', status: 'checked out'}, @@ -55,7 +55,7 @@ describe('Library', function() { ]); }); - it.skip('should be able to handle a search with no results', function() { + it('should be able to handle a search with no results', function() { var collection = [ {title: 'My Life', author: 'Alex', status: 'on shelf'}, {title: 'Adventures', author: 'Sam', status: 'checked out'}, diff --git a/library/library.js b/library/library.js index 2f12195fc..c1d10978e 100644 --- a/library/library.js +++ b/library/library.js @@ -1,3 +1,32 @@ -module.exports = { }; \ No newline at end of file +module.exports = { + issueCard, + searchByAuthor +}; + +function issueCard(name, age) { + var card = { + name: name, + age: age, + numBooksCheckedOut: 0, + isChild: false + } + if (card.age < 12) { + card.isChild = true; + } + return card; +} + +function searchByAuthor(collection, name) { + books = []; + for (var i = 0; i < collection.length; i++) { + if (collection[i].author === name) { + books.push(collection[i]) + } + } + if(books.length === 0) { + return "No book found for search criteria" + } + return books; +} \ No newline at end of file diff --git a/meal-planning/meal-planning-test.js b/meal-planning/meal-planning-test.js index 22d948df4..2f0aae248 100644 --- a/meal-planning/meal-planning-test.js +++ b/meal-planning/meal-planning-test.js @@ -2,7 +2,7 @@ var { createMeal, addDish, calculateCalories } = require('./mealPlanning.js'); var assert = require('chai').assert; describe("Meal Planning", function () { - it.skip("should create a meal with a dynamic type and calorie goal", function() { + it("should create a meal with a dynamic type and calorie goal", function() { var easyBreakfast = createMeal('breakfast', 700); var simpleLunch = createMeal("lunch", 400); @@ -12,19 +12,19 @@ describe("Meal Planning", function () { assert.equal(simpleLunch.calorieGoal, 400); }); - it.skip("should default to having no dishes", function() { + it("should default to having no dishes", function() { var breakfast = createMeal('breakfast', 700); assert.deepEqual(breakfast.dishes, []); }); - it.skip("should add a dish to a meal", function() { + it("should add a dish to a meal", function() { var meal = createMeal("dinner", 500); var mealWithSpaghetti = addDish(meal, { name: "spaghetti", calories: 300 }); assert.deepEqual(mealWithSpaghetti.dishes, [{ name: "spaghetti", calories: 300 }]); }); - it.skip("should add another dish to a meal", function() { + it("should add another dish to a meal", function() { var meal = createMeal("dinner", 600); var mealWithSpaghetti = addDish(meal, { name: "spaghetti", calories: 300 }); var mealWithBread = addDish(mealWithSpaghetti, { name: "garlic bread", calories: 200 }); @@ -32,7 +32,7 @@ describe("Meal Planning", function () { assert.deepEqual(mealWithBread.dishes, [{ name: "spaghetti", calories: 300 }, { name: "garlic bread", calories: 200 }]); }); - it.skip("should only add a dish if it meets or is below the meal's calorie goal", function() { + it("should only add a dish if it meets or is below the meal's calorie goal", function() { var meal = createMeal("dinner", 700); var mealWithBread = addDish(meal, { name: "garlic bread", calories: 200 }); @@ -45,7 +45,7 @@ describe("Meal Planning", function () { assert.equal(mealWithPizza.dishes.length, 0); }); - it.skip("should update the calorieGoal when dishes are added", function() { + it("should update the calorieGoal when dishes are added", function() { var meal = createMeal("breakfast", 400); var mealWithEggs = addDish(meal, { name: "eggs", calories: 200 }); @@ -56,7 +56,7 @@ describe("Meal Planning", function () { assert.equal(mealWithPancake.calorieGoal, 20); }); - it.skip("should calculate the total meal calories", function() { + it("should calculate the total meal calories", function() { var brunch = createMeal("brunch", 700); var brunchWithOmelette = addDish(brunch, { name: "omelette", calories: 450 }); var brunchWithFruit = addDish(brunchWithOmelette, { name: "fruit", calories: 100 }); @@ -66,7 +66,7 @@ describe("Meal Planning", function () { assert.equal(totalCalorieCount, "brunch has a total of 550 calories."); }); - it.skip("should calculate a different meal's calories", function() { + it("should calculate a different meal's calories", function() { var dinner = createMeal("dinner", 1200); var dinnerWithSoup = addDish(dinner, { name: "soup", calories: 250 }); var dinnerWithBeans = addDish(dinnerWithSoup, { name: "green beans", calories: 200 }); diff --git a/meal-planning/mealPlanning.js b/meal-planning/mealPlanning.js index 7334bdcf3..2d13b31bb 100644 --- a/meal-planning/mealPlanning.js +++ b/meal-planning/mealPlanning.js @@ -1,2 +1,31 @@ -module.exports = { } \ No newline at end of file +module.exports = { + createMeal, + addDish, + calculateCalories +} + +function createMeal(meal, calories) { + var meal = { + type: meal, + calorieGoal: calories, + dishes: [] + } + return meal; +} + +function addDish(meal, addMeal) { + if (addMeal.calories < meal.calorieGoal) { + meal.dishes.push(addMeal); + meal.calorieGoal = meal.calorieGoal - addMeal.calories; + } + return meal; +} + +function calculateCalories(meal) { + calories = 0; + for (var i = 0; i < meal.dishes.length; i++) { + calories = calories + meal.dishes[i].calories; + } + return `${meal.type} has a total of ${calories} calories.`; +} \ No newline at end of file diff --git a/mythical-creatures/exercises/dragon.js b/mythical-creatures/exercises/dragon.js index 0037230de..734469645 100644 --- a/mythical-creatures/exercises/dragon.js +++ b/mythical-creatures/exercises/dragon.js @@ -1,8 +1,76 @@ module.exports = { - // createDragon, - // greetRider, - // eat, - // findFireBreathers -} \ No newline at end of file + createDragon, + greetRider, + eat, + findFireBreathers +} + +// goal: write a function that creates an object of dragons with name, rider, and temperment + +// input: three parameters: name, rider, temperment +// output: object + +function createDragon(name, rider, temperment) { + var dragon = { + name: name, + rider: rider, + temperment: temperment, + timesEaten: 0, + hungry: true + + } + + return dragon; +}; + +// goal: write function to greet rider of dragon + +// input: dragon object +// output: 'Hi, !' + +// steps: + // use dot notation to access rider key-value pair + // interpolate rider into greeting + +function greetRider(dragon) { + var rider = dragon.rider; + return `Hi, ${rider}!`; +}; + +// write function that takes in a dragon object and returns + 1 to timesEaten key-value pair and also returns true or false in hungry key value pair + +// input: dragon object +// output: timesEaten++ conditional to check for number of times eaten < 3 + +function eat(dragon) { + dragon.timesEaten++; + if (dragon.timesEaten === 3) { + dragon.hungry = false; + } + return dragon; +}; + + +// write a function that checks an array of objects for aggressive temperment and returns those dragons + +// input: array of dragon objects +// output: dragons with aggressive temperment + +// steps: + // write variable for new dragon array + // iterate through each element in the array of dragons + // access the temperment of each dragon + // if temperment === aggressive, push that dragon to new array + // return new array of dragons + +function findFireBreathers(dragons) { + var aggressiveDragons = []; + for (var i = 0; i < dragons.length; i++) { + if (dragons[i].temperment === 'aggressive') { + aggressiveDragons.push(dragons[i]); + } + } + return aggressiveDragons; +}; \ No newline at end of file diff --git a/mythical-creatures/exercises/hobbit.js b/mythical-creatures/exercises/hobbit.js index 6d9602430..45e18e5ec 100644 --- a/mythical-creatures/exercises/hobbit.js +++ b/mythical-creatures/exercises/hobbit.js @@ -1,9 +1,72 @@ module.exports = { - // createHobbit, - // celebrateBirthday, - // getRing, - // meetPeople, - // findFriends -} \ No newline at end of file + createHobbit, + celebrateBirthday, + getRing, + meetPeople, + findFriends +} + +// goal: write a function that creates an object for a Hobbit with name and age as keys. + +// input: name, age. Two parameters +// output: object with name and age key value pairs. age should start out at 0 if not specified. name should return unknown if not specified. + +function createHobbit(name, age) { + var hobbit = { + name: name, + age: age, + isAdult: false, + isOld: false, + acquaintances: [] + } + if (name === undefined) { + hobbit.name = 'unknown'; + } + if (age === undefined) { + hobbit.age = 0; + } + maturityLevel(hobbit); + return hobbit; +}; + +function maturityLevel(hobbit) { + if (hobbit.age > 32) { + hobbit.isAdult = true; + } + if (hobbit.age >= 101) { + hobbit.isOld = true; + } +}; + +function celebrateBirthday(hobbit) { + hobbit.age++; + maturityLevel(hobbit); + return hobbit; +}; + +function getRing(hobbit) { + if (hobbit.name === 'Frodo') { + return 'Here is the ring!'; + } else { + return 'You can\'t have it!'; + } +}; + +function meetPeople(hobbit, people) { + for (var i = 0; i < people.length; i++) { + hobbit.acquaintances.push(people[i]); + } + return hobbit; +}; + +function findFriends(socialHobbit) { + var friends = []; + for (var i = 0; i < socialHobbit.acquaintances.length; i++) { + if (socialHobbit.acquaintances[i].relationship === "friend") { + friends.push(socialHobbit.acquaintances[i].name); + } + } + return friends; +}; diff --git a/mythical-creatures/exercises/vampire.js b/mythical-creatures/exercises/vampire.js index 930b9e5cc..efd64b735 100644 --- a/mythical-creatures/exercises/vampire.js +++ b/mythical-creatures/exercises/vampire.js @@ -1,9 +1,72 @@ module.exports = { - // createVampire, - // drink, - // findBatLovers, - // encounterDeliciousVictim, - // inquirePlace -} \ No newline at end of file + createVampire, + drink, + findBatLovers, + encounterDeliciousVictim, + inquirePlace +} + + +// create a function that creates an object that includes name, pet, and thirsty. +// pet should default to bat. thirsty should default to true +function createVampire(name, pet) { + var vampire = { + name: name, + pet: pet, + thirsty: true, + ouncesDrank: 0 + } + if (vampire.pet === undefined) { + vampire.pet = 'bat'; + } + return vampire; +}; + +// create a function that takes vampire object as argument and outputs a response + // if thirst === true return 'I WANT TO SUCK YOUR BLOOD!' + +function encounterDeliciousVictim(vampire) { + if (vampire.thirsty === true) { + return 'I WANT TO SUCK YOUR BLOOD!'; + } else { + return 'No thanks, I am too full.' + } +}; + +// create a function that adds 10 ounces to ouncesDrank key. +function drink(vampire) { + if (vampire.thirsty === true) { + vampire.ouncesDrank = vampire.ouncesDrank + 10; + } + if (vampire.ouncesDrank >= 50) { + vampire.thirsty = false; + } + return vampire; +}; + +// create a function that takes in an array of location and a locations and if the location === something in the array, return a statement + +function inquirePlace(locations, location) { + for (var i = 0; i < locations.length; i++) { + if (locations[i] === location) { + return `Yes, I have spent some time in ${locations[i]}.`; + } + } + return `No, I have never been to ${location}.`; +}; + +// should be able to find the vampires with bats. +// function has one parameter for vampire object + // use filter or for loop to find vampires with pet bats + +function findBatLovers(vampire) { + var batLovers = []; + for (var i = 0; i < vampire.length; i++) { + if(vampire[i].pet === 'bat') { + batLovers.push(vampire[i].name); + } + } + return batLovers; +}; \ No newline at end of file diff --git a/mythical-creatures/test/dragon-test.js b/mythical-creatures/test/dragon-test.js index c5f035bd4..559be6da9 100644 --- a/mythical-creatures/test/dragon-test.js +++ b/mythical-creatures/test/dragon-test.js @@ -3,33 +3,33 @@ var { createDragon, greetRider, eat, findFireBreathers} = require('../exercises/ describe('Dragon', function() { - it.skip('should be able to create a dragon with a name', function() { + it('should be able to create a dragon with a name', function() { var dragon = createDragon('Jeff'); assert.equal(dragon.name, 'Jeff'); }); - it.skip('should be able to have a different name', function() { + it('should be able to have a different name', function() { var dragon = createDragon('Louisa'); assert.equal(dragon.name, 'Louisa'); }); - it.skip('should have a rider', function() { + it('should have a rider', function() { var dragon = createDragon('Saphira', 'Eragon'); assert.equal(dragon.name, 'Saphira'); assert.equal(dragon.rider, 'Eragon'); }); - it.skip('should be able to have a different rider', function() { + it('should be able to have a different rider', function() { var dragon = createDragon('Elliot', 'Pete'); assert.equal(dragon.name, 'Elliot'); assert.equal(dragon.rider, 'Pete'); }); - it.skip('should have a temperment', function() { + it('should have a temperment', function() { var dragon = createDragon('Saphira', 'Eragon', 'gentle'); assert.equal(dragon.name, 'Saphira'); @@ -37,7 +37,7 @@ describe('Dragon', function() { assert.equal(dragon.temperment, 'gentle'); }); - it.skip('should be able to have different temperments', function() { + it('should be able to have different temperments', function() { var dragon1 = createDragon('Gray', 'Marley', 'aggressive'); var dragon2 = createDragon('Sky', 'Susie', 'gentle'); @@ -51,7 +51,7 @@ describe('Dragon', function() { assert.equal(dragon2.temperment, 'gentle'); }); - it.skip('should greet their rider', function() { + it('should greet their rider', function() { var dragon1 = createDragon('Gray', 'Marley', 'aggressive'); var dragon2 = createDragon('Sky', 'Susie', 'gentle'); @@ -62,19 +62,19 @@ describe('Dragon', function() { assert.equal(greeting2, 'Hi, Susie!'); }); - it.skip('should start off having eaten 0 times', function() { + it('should start off having eaten 0 times', function() { var dragon = createDragon('Mushu', 'Mulan', 'aggressive'); assert.equal(dragon.timesEaten, 0); }); - it.skip('should start off being hungry', function() { + it('should start off being hungry', function() { var dragon = createDragon('Mushu', 'Mulan', 'aggressive'); assert.equal(dragon.hungry, true); }); - it.skip('should be full after eating 3 times', function() { + it('should be full after eating 3 times', function() { var dragon = createDragon('Lady Vox', 'Emily', 'gentle'); var fedDragon = eat(dragon); @@ -94,7 +94,7 @@ describe('Dragon', function() { }); //Spicy: - it.skip('should be a fireBreather if aggressive in temperment', function() { + it('should be a fireBreather if aggressive in temperment', function() { var dragon1 = createDragon('Gray', 'Marley', 'aggressive'); var dragon2 = createDragon('Sky', 'Susie', 'gentle'); var dragon3 = createDragon('Mushu', 'Mulan', 'aggressive'); diff --git a/mythical-creatures/test/hobbit-test.js b/mythical-creatures/test/hobbit-test.js index fa53686c0..bd3136ce7 100644 --- a/mythical-creatures/test/hobbit-test.js +++ b/mythical-creatures/test/hobbit-test.js @@ -3,7 +3,7 @@ var {createHobbit, celebrateBirthday, getRing, meetPeople, findFriends} = requir describe('Hobbit', function() { - it.skip('should make a hobbit with a name and age', function() { + it('should make a hobbit with a name and age', function() { var bilbo = createHobbit('Bilbo', 0); var mark = createHobbit('Mark', 5); @@ -14,20 +14,20 @@ describe('Hobbit', function() { assert.equal(mark.age, 5); }); - it.skip('should start out 0 years old if not specified', function() { + it('should start out 0 years old if not specified', function() { var bilbo = createHobbit('Bilbo'); assert.equal(bilbo.age, 0); }); - it.skip('should return an object with defaults if nothing passed', function() { + it('should return an object with defaults if nothing passed', function() { var hobbit = createHobbit(); assert.equal(hobbit.name, 'unknown'); assert.equal(hobbit.age, 0); }); - it.skip('should gain 1 year after every birthday', function() { + it('should gain 1 year after every birthday', function() { var hobbit = createHobbit('Meriadoc'); var olderHobbit = celebrateBirthday(hobbit); @@ -37,7 +37,7 @@ describe('Hobbit', function() { assert.equal(evenOlderStillHobbit.age, 3); }); - it.skip('should be considered a child at the age of 32', function() { + it('should be considered a child at the age of 32', function() { var taylor = createHobbit('Taylor', 31); assert.equal(taylor.age, 31); @@ -49,7 +49,7 @@ describe('Hobbit', function() { assert.equal(olderTaylor.isAdult, false); }); - it.skip('should be considered an adult at 33', function() { + it('should be considered an adult at 33', function() { var ryan = createHobbit('Ryan', 32); var olderRyan = celebrateBirthday(ryan); @@ -58,7 +58,7 @@ describe('Hobbit', function() { assert.equal(olderRyan.isAdult, true); }); - it.skip('should be considered old at the age of 101', function() { + it('should be considered old at the age of 101', function() { var samwise = createHobbit('Samwise', 99); assert.equal(samwise.age, 99) @@ -75,7 +75,7 @@ describe('Hobbit', function() { assert.equal(hundredAndOneSamwise.isOld, true) }); - it.skip('should be able to get the ring if its name is Frodo', function() { + it('should be able to get the ring if its name is Frodo', function() { var hobbit1 = createHobbit('Frodo'); var hobbit2 = createHobbit('Samwise'); @@ -83,7 +83,7 @@ describe('Hobbit', function() { assert.equal(getRing(hobbit2), 'You can\'t have it!'); }); - it.skip('should start with no acquaintances', function() { + it('should start with no acquaintances', function() { var bilbo = createHobbit('Bilbo'); assert.equal(bilbo.name, 'Bilbo'); @@ -92,7 +92,7 @@ describe('Hobbit', function() { }); //Spicy - it.skip('should be able to meet people', function() { + it('should be able to meet people', function() { var people = [ {name: 'Nick', relationship: 'friend'} ]; var bilbo = createHobbit('Bilbo'); @@ -104,7 +104,7 @@ describe('Hobbit', function() { assert.equal(socialBilbo.acquaintances[0].relationship, 'friend'); }); - it.skip('should be able to meet several people at once', function() { + it('should be able to meet several people at once', function() { var people = [ {name: 'Nick', relationship: 'friend'}, {name: 'Ben', relationship: 'enemy'} ]; var bilbo = createHobbit('Bilbo'); @@ -117,7 +117,7 @@ describe('Hobbit', function() { assert.deepEqual(socialBilbo.acquaintances, people); }); - it.skip('should be able to meet people on multiple occasions', function() { + it('should be able to meet people on multiple occasions', function() { var nick = {name: 'Nick', relationship: 'friend'}; var ben = {name: 'Ben', relationship: 'enemy'}; var people = [ nick, ben ]; @@ -138,7 +138,7 @@ describe('Hobbit', function() { assert.deepEqual(moreSocialBilbo.acquaintances, [nick, ben, trisha, dustin]); }); - it.skip('should be able to identify which acquaintances are friends ', function() { + it('should be able to identify which acquaintances are friends ', function() { var foster = {name: 'Foster', relationship: 'friend'}; var allie = {name: 'Allie', relationship: 'enemy'}; var garrett = {name: 'Garrett', relationship: 'enemy'}; diff --git a/mythical-creatures/test/vampire-test.js b/mythical-creatures/test/vampire-test.js index b63b1565e..712372a67 100644 --- a/mythical-creatures/test/vampire-test.js +++ b/mythical-creatures/test/vampire-test.js @@ -3,20 +3,20 @@ var {createVampire, drink, findBatLovers, encounterDeliciousVictim, inquirePlace describe('Vampire', function() { - it.skip('should create a vampire', function() { + it('should create a vampire', function() { var vampire = createVampire('Jhun'); assert.equal(vampire.name, 'Jhun'); }); - it.skip('should have a pet bat as a default', function() { + it('should have a pet bat as a default', function() { var vampire = createVampire('Brittany'); assert.equal(vampire.name, 'Brittany'); assert.equal(vampire.pet, 'bat'); }); - it.skip('should be able to take an argument for pet', function() { + it('should be able to take an argument for pet', function() { var vampire = createVampire('Jeff', 'fox'); var vampira = createVampire('Esme', 'armadillo'); @@ -24,13 +24,13 @@ describe('Vampire', function() { assert.equal(vampira.pet, 'armadillo'); }); - it.skip('should be thirsty', function() { + it('should be thirsty', function() { var vampire = createVampire('Andy'); assert.equal(vampire.thirsty, true); }); - it.skip('should should at victim when thirsty', function() { + it('should should at victim when thirsty', function() { var vampire = createVampire('Andy'); var expectedResponse = 'I WANT TO SUCK YOUR BLOOD!' @@ -39,13 +39,13 @@ describe('Vampire', function() { assert.equal(shout, expectedResponse); }); - it.skip('should be start with no ounces of blood drank', function() { + it('should be start with no ounces of blood drank', function() { var vampire = createVampire('Bobby'); assert.equal(vampire.ouncesDrank, 0); }); - it.skip('should drink 10 ounces of blood at a time', function() { + it('should drink 10 ounces of blood at a time', function() { var vampire = createVampire('Margot'); var drankOnceVamp = drink(vampire); @@ -61,7 +61,7 @@ describe('Vampire', function() { assert.equal(drankThriceVamp.ouncesDrank, 30); }); - it.skip('should no longer be thirsty after drinking 50 ounces', function() { + it('should no longer be thirsty after drinking 50 ounces', function() { var vampire = createVampire('Javi'); var drankOnceVamp = drink(vampire); @@ -74,7 +74,7 @@ describe('Vampire', function() { assert.equal(drank5xsVamp.thirsty, false); }); - it.skip('should not drink more ounces when not thirsty', function() { + it('should not drink more ounces when not thirsty', function() { var vampire = createVampire('Javi'); var drankOnceVamp = drink(vampire); @@ -91,7 +91,7 @@ describe('Vampire', function() { assert.equal(notDrinking6xsVamp.ouncesDrank, 50); }); - it.skip('should refuse blood from victim when not thirsty', function() { + it('should refuse blood from victim when not thirsty', function() { var vampire = createVampire('Javi'); var drankOnceVamp = drink(vampire); @@ -108,7 +108,7 @@ describe('Vampire', function() { assert.equal(response, `No thanks, I am too full.`); }); - it.skip('should say if its been to a location', function() { + it('should say if its been to a location', function() { var locations = ['Transylvania', 'Washington', 'New Orleans', 'Mystic Falls']; var response = inquirePlace(locations, 'New Orleans'); @@ -117,7 +117,7 @@ describe('Vampire', function() { assert.deepEqual(response, expectedResponse); }); - it.skip('should say if its not been to a location', function() { + it('should say if its not been to a location', function() { var locations = ['Transylvania', 'Washington', 'New Orleans', 'Mystic Falls']; var response = inquirePlace(locations, 'Idaho'); @@ -127,7 +127,7 @@ describe('Vampire', function() { }); //Spicy - it.skip('should be able to find the vampires with bats', function() { + it('should be able to find the vampires with bats', function() { var javi = createVampire('Javi'); var brittany = createVampire('Brittany'); var jeff = createVampire('Jeff', 'fox'); diff --git a/package-lock.json b/package-lock.json index a14533844..6c29b90e4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,8 +1,288 @@ { "name": "foundations", "version": "1.0.0", - "lockfileVersion": 1, + "lockfileVersion": 2, "requires": true, + "packages": { + "": { + "name": "foundations", + "version": "1.0.0", + "license": "MIT", + "dependencies": { + "chai": "^4.2.0", + "mocha": "^5.2.0" + } + }, + "node_modules/assertion-error": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/assertion-error/-/assertion-error-1.1.0.tgz", + "integrity": "sha512-jgsaNduz+ndvGyFt3uSuWqvy4lCnIJiovtouQN5JZHOKCS2QuhEdbcQHFhVksz2N2U9hXJo8odG7ETyWlEeuDw==", + "engines": { + "node": "*" + } + }, + "node_modules/balanced-match": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz", + "integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=" + }, + "node_modules/brace-expansion": { + "version": "1.1.11", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", + "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", + "dependencies": { + "balanced-match": "^1.0.0", + "concat-map": "0.0.1" + } + }, + "node_modules/browser-stdout": { + "version": "1.3.1", + "resolved": "https://registry.npmjs.org/browser-stdout/-/browser-stdout-1.3.1.tgz", + "integrity": "sha512-qhAVI1+Av2X7qelOfAIYwXONood6XlZE/fXaBSmW/T5SzLAmCgzi+eiWE7fUvbHaeNBQH13UftjpXxsfLkMpgw==" + }, + "node_modules/chai": { + "version": "4.2.0", + "resolved": "https://registry.npmjs.org/chai/-/chai-4.2.0.tgz", + "integrity": "sha512-XQU3bhBukrOsQCuwZndwGcCVQHyZi53fQ6Ys1Fym7E4olpIqqZZhhoFJoaKVvV17lWQoXYwgWN2nF5crA8J2jw==", + "dependencies": { + "assertion-error": "^1.1.0", + "check-error": "^1.0.2", + "deep-eql": "^3.0.1", + "get-func-name": "^2.0.0", + "pathval": "^1.1.0", + "type-detect": "^4.0.5" + }, + "engines": { + "node": ">=4" + } + }, + "node_modules/check-error": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/check-error/-/check-error-1.0.2.tgz", + "integrity": "sha1-V00xLt2Iu13YkS6Sht1sCu1KrII=", + "engines": { + "node": "*" + } + }, + "node_modules/commander": { + "version": "2.15.1", + "resolved": "http://registry.npmjs.org/commander/-/commander-2.15.1.tgz", + "integrity": "sha512-VlfT9F3V0v+jr4yxPc5gg9s62/fIVWsd2Bk2iD435um1NlGMYdVCq+MjcXnhYq2icNOizHr1kK+5TI6H0Hy0ag==" + }, + "node_modules/concat-map": { + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", + "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=" + }, + "node_modules/debug": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz", + "integrity": "sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==", + "dependencies": { + "ms": "2.0.0" + } + }, + "node_modules/deep-eql": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/deep-eql/-/deep-eql-3.0.1.tgz", + "integrity": "sha512-+QeIQyN5ZuO+3Uk5DYh6/1eKO0m0YmJFGNmFHGACpf1ClL1nmlV/p4gNgbl2pJGxgXb4faqo6UE+M5ACEMyVcw==", + "dependencies": { + "type-detect": "^4.0.0" + }, + "engines": { + "node": ">=0.12" + } + }, + "node_modules/diff": { + "version": "3.5.0", + "resolved": "https://registry.npmjs.org/diff/-/diff-3.5.0.tgz", + "integrity": "sha512-A46qtFgd+g7pDZinpnwiRJtxbC1hpgf0uzP3iG89scHk0AUC7A1TGxf5OiiOUv/JMZR8GOt8hL900hV0bOy5xA==", + "engines": { + "node": ">=0.3.1" + } + }, + "node_modules/escape-string-regexp": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz", + "integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=", + "engines": { + "node": ">=0.8.0" + } + }, + "node_modules/fs.realpath": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", + "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=" + }, + "node_modules/get-func-name": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/get-func-name/-/get-func-name-2.0.0.tgz", + "integrity": "sha1-6td0q+5y4gQJQzoGY2YCPdaIekE=", + "engines": { + "node": "*" + } + }, + "node_modules/glob": { + "version": "7.1.2", + "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.2.tgz", + "integrity": "sha512-MJTUg1kjuLeQCJ+ccE4Vpa6kKVXkPYJ2mOCQyUuKLcLQsdrMCpBPUi8qVE6+YuaJkozeA9NusTAw3hLr8Xe5EQ==", + "dependencies": { + "fs.realpath": "^1.0.0", + "inflight": "^1.0.4", + "inherits": "2", + "minimatch": "^3.0.4", + "once": "^1.3.0", + "path-is-absolute": "^1.0.0" + }, + "engines": { + "node": "*" + } + }, + "node_modules/growl": { + "version": "1.10.5", + "resolved": "https://registry.npmjs.org/growl/-/growl-1.10.5.tgz", + "integrity": "sha512-qBr4OuELkhPenW6goKVXiv47US3clb3/IbuWF9KNKEijAy9oeHxU9IgzjvJhHkUzhaj7rOUD7+YGWqUjLp5oSA==", + "engines": { + "node": ">=4.x" + } + }, + "node_modules/has-flag": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz", + "integrity": "sha1-tdRU3CGZriJWmfNGfloH87lVuv0=", + "engines": { + "node": ">=4" + } + }, + "node_modules/he": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/he/-/he-1.1.1.tgz", + "integrity": "sha1-k0EP0hsAlzUVH4howvJx80J+I/0=", + "bin": { + "he": "bin/he" + } + }, + "node_modules/inflight": { + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", + "integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=", + "dependencies": { + "once": "^1.3.0", + "wrappy": "1" + } + }, + "node_modules/inherits": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz", + "integrity": "sha1-Yzwsg+PaQqUC9SRmAiSA9CCCYd4=" + }, + "node_modules/minimatch": { + "version": "3.0.4", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", + "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==", + "dependencies": { + "brace-expansion": "^1.1.7" + }, + "engines": { + "node": "*" + } + }, + "node_modules/minimist": { + "version": "0.0.8", + "resolved": "http://registry.npmjs.org/minimist/-/minimist-0.0.8.tgz", + "integrity": "sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0=" + }, + "node_modules/mkdirp": { + "version": "0.5.1", + "resolved": "http://registry.npmjs.org/mkdirp/-/mkdirp-0.5.1.tgz", + "integrity": "sha1-MAV0OOrGz3+MR2fzhkjWaX11yQM=", + "deprecated": "Legacy versions of mkdirp are no longer supported. Please update to mkdirp 1.x. (Note that the API surface has changed to use Promises in 1.x.)", + "dependencies": { + "minimist": "0.0.8" + }, + "bin": { + "mkdirp": "bin/cmd.js" + } + }, + "node_modules/mocha": { + "version": "5.2.0", + "resolved": "https://registry.npmjs.org/mocha/-/mocha-5.2.0.tgz", + "integrity": "sha512-2IUgKDhc3J7Uug+FxMXuqIyYzH7gJjXECKe/w43IGgQHTSj3InJi+yAA7T24L9bQMRKiUEHxEX37G5JpVUGLcQ==", + "dependencies": { + "browser-stdout": "1.3.1", + "commander": "2.15.1", + "debug": "3.1.0", + "diff": "3.5.0", + "escape-string-regexp": "1.0.5", + "glob": "7.1.2", + "growl": "1.10.5", + "he": "1.1.1", + "minimatch": "3.0.4", + "mkdirp": "0.5.1", + "supports-color": "5.4.0" + }, + "bin": { + "_mocha": "bin/_mocha", + "mocha": "bin/mocha" + }, + "engines": { + "node": ">= 4.0.0" + } + }, + "node_modules/ms": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", + "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=" + }, + "node_modules/once": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", + "integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=", + "dependencies": { + "wrappy": "1" + } + }, + "node_modules/path-is-absolute": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", + "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=", + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/pathval": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/pathval/-/pathval-1.1.0.tgz", + "integrity": "sha1-uULm1L3mUwBe9rcTYd74cn0GReA=", + "engines": { + "node": "*" + } + }, + "node_modules/supports-color": { + "version": "5.4.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.4.0.tgz", + "integrity": "sha512-zjaXglF5nnWpsq470jSv6P9DwPvgLkuapYmfDm3JWOm0vkNTVF2tI4UrN2r6jH1qM/uc/WtxYY1hYoA2dOKj5w==", + "dependencies": { + "has-flag": "^3.0.0" + }, + "engines": { + "node": ">=4" + } + }, + "node_modules/type-detect": { + "version": "4.0.8", + "resolved": "https://registry.npmjs.org/type-detect/-/type-detect-4.0.8.tgz", + "integrity": "sha512-0fr/mIH1dlO+x7TlcMy+bIDqKPsw/70tVyeHW787goQjhmqaZe10uwLujubK9q9Lg6Fiho1KUKDYz0Z7k7g5/g==", + "engines": { + "node": ">=4" + } + }, + "node_modules/wrappy": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", + "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=" + } + }, "dependencies": { "assertion-error": { "version": "1.1.0", diff --git a/restaurant/meal.js b/restaurant/meal.js index cdda50fa5..9ca169a01 100644 --- a/restaurant/meal.js +++ b/restaurant/meal.js @@ -1,2 +1,55 @@ -module.exports = { }; +module.exports = { + createMeal, + getMade, + createOrder, + cookMeal, + listOrders, + announceMeal +}; + +function createMeal(name, specialRequests, tableNumber) { + var meal = { + name: name, + specialRequests: specialRequests, + tableNumber: tableNumber, + complete: false + } + return meal; +} + +function getMade(meal) { + meal.complete = true; + return meal; +} + +function announceMeal(meal) { + if (meal.complete) { + return `Order up - ${meal.name} for table ${meal.tableNumber}!`; + } + return `This ${meal.name} is not completed yet` +} + +function createOrder(order) { + var order = { + tableNumber: order.tableNumber, + meals: order.meals, + completedMeals: [] + } + return order; +} + +function cookMeal(order, meal) { + if(order.tableNumber === meal.tableNumber) { + order.completedMeals.push(meal.name); + } + return order; +} + +function listOrders(order) { + var orderNames = []; + for (var i = 0; i < order.meals.length; i++) { + orderNames.push(order.meals[i].name); + } + return orderNames; +} \ No newline at end of file diff --git a/spa/customer-test.js b/spa/customer-test.js index bc847541d..1089e4abd 100644 --- a/spa/customer-test.js +++ b/spa/customer-test.js @@ -3,7 +3,7 @@ var assert = require('chai').assert; describe('Customer', function () { - it.skip('should create a customer', function () { + it('should create a customer', function () { var kayla = createCustomer('Kayla', 100, ['acupuncture', 'seaweed wrap']) var ramiro = createCustomer('Ramiro', 0,[]) assert.equal(kayla.name, 'Kayla') @@ -13,12 +13,12 @@ describe('Customer', function () { assert.equal(ramiro.bill, '0') assert.deepEqual(ramiro.bookings, []) }) - it.skip('should start with no booked services',function(){ + it('should start with no booked services',function(){ var customer = createCustomer('Leta', 0) assert.deepEqual(customer.bookings, []) }) -it.skip('should greet customers', function () { +it('should greet customers', function () { var nick = createCustomer('Nick', 0, []) var tracey = createCustomer('Tracey', 50, ['facial']) var welcomeNick = greeting(nick) @@ -28,7 +28,7 @@ it.skip('should greet customers', function () { assert.equal(welcomeTracey, 'Tracey! Welcome back to Happy Spa') }) -it.skip('should create service', function(){ +it('should create service', function(){ var facialService = createService('facial', 50) var emptyService = createService() assert.deepEqual(facialService, {name: 'facial', cost:50 }) @@ -36,7 +36,7 @@ it.skip('should create service', function(){ }) -it.skip('should book services', function(){ +it('should book services', function(){ var travis = createCustomer('Travis', 10, ['steam room']) var will = createCustomer('Will', 0, []) var massage = createService('massage', 50) @@ -50,7 +50,7 @@ it.skip('should book services', function(){ }) -it.skip('should rack up a bill', function(){ +it('should rack up a bill', function(){ var nik = createCustomer('Nik', 0 , []) var footMassage = createService('foot massage', 65) var facial = createService('facial', 50) @@ -60,7 +60,7 @@ it.skip('should rack up a bill', function(){ assert.deepEqual(nikFootMassage.bookings, ['foot massage','facial']) assert.deepEqual(nikFacial.bill, 115) }) -it.skip('should be able to find which services are affordable based on gift card amount', function(){ +it('should be able to find which services are affordable based on gift card amount', function(){ var allServices = [ {name:'sauna', price:10}, {name:'massage', price:50}, diff --git a/spa/customer.js b/spa/customer.js index 4211f29d2..7617895cc 100644 --- a/spa/customer.js +++ b/spa/customer.js @@ -1,2 +1,54 @@ -module.exports = { } +module.exports = { + createCustomer, + greeting, + bookServices, + createService, + applyGiftCard + } + +function createCustomer(name, bill, bookings) { + var customer = { + name: name, + bill: bill, + bookings: bookings + } + if (!bookings) { + customer.bookings = []; + } + return customer; +} + +function greeting(customer) { + if (!customer.bill) { + return `${customer.name}! Welcome to Happy Spa` + } + return `${customer.name}! Welcome back to Happy Spa` +} + +function createService(service, price) { + if (!service && !price) { + return "Please provide service name and cost." + } + var service = { + name: service, + cost: price + } + return service; +} + +function bookServices(customer, service) { + customer.bookings.push(service.name); + customer.bill = customer.bill + service.cost; + return customer; +} + +function applyGiftCard(services, amount) { + var availableServices = []; + for (var i = 0; i < services.length; i++) { + if (services[i].price <= amount) { + availableServices.push(services[i].name); + } + } + return availableServices; +} \ No newline at end of file diff --git a/spotify/collection-test.js b/spotify/collection-test.js index 3bfe7b63d..f05b775af 100644 --- a/spotify/collection-test.js +++ b/spotify/collection-test.js @@ -1,28 +1,28 @@ -var { createCollection, createTrack,reviewTrack, addTrack,getTotalDuration, findTracksByArtist } = require("./collection") +var { createCollection, createTrack, reviewTrack, addTrack, getTotalDuration, findTracksByArtist } = require("./collection") var assert = require('chai').assert; describe('Spotify collections', function() { - it.skip('should create a collection', function() { + it('should create a collection', function() { var chillHits = createCollection('Chill Hits', 'A collection of relaxing songs'); assert.equal(chillHits.name, 'Chill Hits'); assert.equal(chillHits.description, 'A collection of relaxing songs'); assert.deepEqual(chillHits.tracks, []); }); - it.skip('should create track', function() { + it('should create track', function() { var track1 = createTrack('Sunset', 'The Midnight', 270); assert.deepEqual(track1.title,'Sunset'); assert.deepEqual(track1.duration,270); assert.deepEqual(track1.artist, 'The Midnight') }); - it.skip("should return default if nothing is passed", function(){ + it("should return default if nothing is passed", function(){ var emptyTrack = createTrack() assert.deepEqual(emptyTrack, {title:'unknown',artist:'unknown', duration:0, }); }) - it.skip('should only appreciate the talent of Red Hot Chili Peppers', function() { + it('should only appreciate the talent of Red Hot Chili Peppers', function() { var track1 = createTrack('Californication', 'Red Hot Chili Peppers', 321); var track2 = createTrack('Otherside', 'Red Hot Chili Peppers', 255); var track3 = createTrack('Beautiful Day', 'U2', 246); @@ -37,7 +37,7 @@ describe('Spotify collections', function() { assert.equal(review3, 'I wish this was a Red Hot Chili Peppers song.'); }); - it.skip('should add one track to a collection', function() { + it('should add one track to a collection', function() { var chillHits = createCollection('Chill Hits', 'A collection of relaxing songs'); var track1 = createTrack('Sunset', 'The Midnight', 270); var chillHitsWith1Track = addTrack(chillHits, track1); @@ -45,7 +45,7 @@ describe('Spotify collections', function() { assert.deepEqual(chillHitsWith1Track.tracks, [track1]); }); - it.skip('should add tracks to a collection', function() { + it('should add tracks to a collection', function() { var chillHits = createCollection('Chill Hits', 'A collection of relaxing songs'); var track1 = createTrack('Sunset', 'The Midnight', 270); var track2 = createTrack('Dreaming', 'Small Sails', 215); @@ -55,7 +55,7 @@ describe('Spotify collections', function() { assert.deepEqual(chillHitsWith2Track.tracks, [track1, track2]); }); - it.skip('should calculate the total duration of a collection', function() { + it('should calculate the total duration of a collection', function() { var chillHits = createCollection('Chill Hits', 'A collection of relaxing songs'); var track1 = createTrack('Sunset', 'The Midnight', 270); var track2 = createTrack('Dreaming', 'Small Sails', 215); @@ -64,7 +64,7 @@ describe('Spotify collections', function() { assert.equal(getTotalDuration(chillHitsWith2Track), 485); }); - it.skip('should find tracks by artist in a collection', function() { + it('should find tracks by artist in a collection', function() { var chillHits = createCollection('Chill Hits', 'A collection of relaxing songs'); var track1 = createTrack('Sunset', 'The Midnight', 270); var track2 = createTrack('Dreaming', 'Small Sails', 215); diff --git a/spotify/collection.js b/spotify/collection.js index 038214d39..fdcf987bb 100644 --- a/spotify/collection.js +++ b/spotify/collection.js @@ -1,4 +1,68 @@ - module.exports = { } \ No newline at end of file + module.exports = { + createCollection, + createTrack, + reviewTrack, + addTrack, + getTotalDuration, + findTracksByArtist + } + +function createCollection(name, description) { + var collection = { + name: name, + description: description, + tracks: [] + } + return collection; +} + +function createTrack(title, artist, duration) { + var track = { + title: title, + artist: artist, + duration: duration + } + if (!track.title) { + track.title = 'unknown'; + } + if (!track.artist) { + track.artist = 'unknown'; + } + if (!track.duration) { + track.duration = 0; + } + return track; +} + +function reviewTrack(track) { + if (track.artist === 'Red Hot Chili Peppers') { + return `The song ${track.title} rules!` + } + return "I wish this was a Red Hot Chili Peppers song." +} + +function addTrack(collection, track) { + collection.tracks.push(track); + return collection; +} + +function getTotalDuration(collection) { + var duration = 0; + for (var i = 0; i < collection.tracks.length; i++) { + duration = duration + collection.tracks[i].duration; + } + return duration; +} + +function findTracksByArtist(collection, artist) { + var songs = []; + for (var i = 0; i < collection.tracks.length; i++) { + if (collection.tracks[i].artist === artist) { + songs.push(collection.tracks[i]) + } + } + return songs; +} \ No newline at end of file diff --git a/tacoStand/index-test.js b/tacoStand/index-test.js index 1c0b18bca..593b164b5 100644 --- a/tacoStand/index-test.js +++ b/tacoStand/index-test.js @@ -3,7 +3,7 @@ var { createIngredient, createTaco, addIngredientToTaco, calculatePrice } = requ describe('taco stand', function() { describe('createIngredient', function() { - it.skip('should take a name and price', function() { + it('should take a name and price', function() { const ingredient1 = createIngredient('chicken', 2.50) const ingredient2 = createIngredient('steak', 3.25) @@ -13,7 +13,7 @@ describe('taco stand', function() { assert.equal(ingredient2.price, 3.25) }) - it.skip('should return an ingredient with defaults if nothing is passed', function() { + it('should return an ingredient with defaults if nothing is passed', function() { const defaultIngredient = createIngredient() assert.equal(defaultIngredient.name, 'unknown') @@ -22,25 +22,25 @@ describe('taco stand', function() { }) describe('createTaco', function() { - it.skip('should have a name', function() { + it('should have a name', function() { const southwestTaco = createTaco('southwestern') assert.equal(southwestTaco.name, 'southwestern') }) - it.skip('should have a default name if none provided', function() { + it('should have a default name if none provided', function() { const southwestTaco = createTaco() assert.equal(southwestTaco.name, 'custom') }) - it.skip('should have no ingredients by default', function() { + it('should have no ingredients by default', function() { const bajaTaco = createTaco('baja') assert.deepEqual(bajaTaco.ingredients, []) }) - it.skip('should be able to create a taco with ingredients', function() { + it('should be able to create a taco with ingredients', function() { const fish = createIngredient('fish', 2.95) const hotSauce = createIngredient('siracha mayo', 0.95) const lettuce = createIngredient('lettuce', 0.50) @@ -53,7 +53,7 @@ describe('taco stand', function() { }) describe('addIngredientToTaco', function() { - it.skip('should be able to add an ingredient to a taco', function() { + it('should be able to add an ingredient to a taco', function() { const steak = createIngredient('steak', 3.50) const basicSteakTaco = createTaco('basic steak', [steak]) @@ -63,7 +63,7 @@ describe('taco stand', function() { assert.deepEqual(lettuceAddedTaco.ingredients, [steak, lettuce]) }) - it.skip('should return the taco unchanged if no ingredient is included', function() { + it('should return the taco unchanged if no ingredient is included', function() { const steak = createIngredient('steak', 3.50) const basicSteakTaco = createTaco('basic steak', [steak]) @@ -74,7 +74,7 @@ describe('taco stand', function() { }) describe('calculatePrice', function() { - it.skip('should calculate the price of a single ingredient taco', function() { + it('should calculate the price of a single ingredient taco', function() { const steak = createIngredient('steak', 3.50) const basicSteakTaco = createTaco('basic steak', [steak]) @@ -83,7 +83,7 @@ describe('taco stand', function() { assert.equal(price, 3.50) }) - it.skip('should calculate the price of a 2 ingredient taco', function() { + it('should calculate the price of a 2 ingredient taco', function() { const steak = createIngredient('steak', 3.50) const lettuce = createIngredient('lettuce', 0.50) const steakTaco = createTaco('steak', [steak, lettuce]) @@ -93,7 +93,7 @@ describe('taco stand', function() { assert.equal(price, 4.00) }) - it.skip('should calculate the price of a many ingredient taco', function() { + it('should calculate the price of a many ingredient taco', function() { const steak = createIngredient('steak', 3.50) const lettuce = createIngredient('lettuce', 0.50) const hotSauce = createIngredient('siracha mayo', 0.95) diff --git a/tacoStand/index.js b/tacoStand/index.js index 5704bb728..dfa19aafe 100644 --- a/tacoStand/index.js +++ b/tacoStand/index.js @@ -1,2 +1,48 @@ -module.exports = {} +module.exports = { + createIngredient, + createTaco, + addIngredientToTaco, + calculatePrice +} + +function createIngredient(name, price) { + var taco = { + name: name, + price: price + } + if (!name) { + taco.name = 'unknown'; + } + if (!price) { + taco.price = 0.00; + } + return taco; +} + +function createTaco(name, ingredients) { + var taco = { + name: name, + ingredients: ingredients + } + if (!name) { + taco.name = 'custom'; + } + if (!ingredients) { + taco.ingredients = [] + } + return taco; +} + +function addIngredientToTaco(taco, ingredient) { + taco.ingredients.push(ingredient) + return taco +} + +function calculatePrice(taco) { + var price = 0; + for (var i = 0; i < taco.ingredients.length; i++) { + price = price + taco.ingredients[i].price; + } + return price; +} \ No newline at end of file