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
function listDestinations(destinations) { | |
let response = "I can tell you about our current recommended destinations. Which one do you want to hear about? "; | |
let locations = getLocations(destinations); | |
response += locations.join("; ") + ". "; | |
response += "Enter a location for more info." | |
return response; | |
} | |
function getLocations(destinations) { | |
let locations = []; |
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
function shouldWeOrderThisCandy(inventory, candy){ | |
for (let i=0; i<inventory.length; i++){ | |
if (inventory[i].inStock < inventory[i].weeklyAverage && inventory[i].candy===candy) | |
return true; | |
} | |
} | |
return false; | |
} |
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
function userHasVisitedParkOnWishlist(users, user1, user2) { | |
const vist = users[user1].visited; | |
const wish = users[user2].wishlist; | |
return vist.some((park) => wish.includes(park)); | |
} | |
function getUsersForUserWishlist(users, user1) { | |
const usernames = Object.keys(users); | |
return usernames.reduce((acc, username) => { | |
let visited = userHasVisitedParkOnWishlist(users, username, user1); |
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
function numberOfBorrows(account, books) { | |
// match account id with books borrows id | |
acc = 0; | |
books.forEach(book => { | |
for (let i = 0; i < book.borrows.length; i++) { | |
console.log(book.borrows[i].id); | |
if (book.borrows[i].id === account.id) { | |
acc += 1; | |
} | |
} |
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
const { welcome, goodbye, tell } = require("../utils/fortune-teller"); | |
function getFortune(question) { | |
tell(question).then(msg => { | |
console.log(`Your question was: ${question}`); | |
console.log(`Your fortune is: ${msg}`)}) | |
.catch(err => console.log('There was an error: A question is required...')); | |
} | |
function fullSession(question) { |
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
function getFortune(question) { | |
tell(question).then(msg => { | |
console.log(`Your question was: ${question}`); | |
console.log(`Your fortune is: ${msg}`)}) | |
.catch(err => console.log('There was an error: A question is required...')); | |
} |
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
function secretPasscode(code) { | |
let errors = []; | |
if (code.length < 14) errors.push("Code is too short!"); | |
if (code.length > 14) errors.push("Code is too long!"); | |
if (!code.includes("-")) errors.push("Code is missing a '-'."); | |
if (code !== "jWhyYFh-eTx3qt") errors.push("Code is incorrect."); | |
if (errors.length > 0) { | |
throw errors; | |
} |
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
function getWishlistParksForUser(parks, users, username) { | |
const wish = users[username].wishlist | |
return parks.filter((park) => wish.includes(park.id)); | |
} | |
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
function allCandyOrders(inventory) { | |
let result = {}; | |
for (let i=0; i<inventory.length; i++) { | |
if (inventory[i].inStock < inventory[i].weeklyAverage) { | |
result[inventory[i].candy]= inventory[i].weeklyAverage * 2; | |
} else { | |
result[inventory[i].candy] = 0; | |
} | |
} | |
return result; |
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
function getMostCommonGenres(books) { | |
let countObj = {}; | |
books.forEach(aBook => { | |
if (countObj[aBook.genre] != null) { | |
countObj[aBook.genre]++; | |
} else { | |
countObj[aBook.genre] = 1; | |
} | |
}); | |
let countArray = []; |