Skip to content

Instantly share code, notes, and snippets.

@McLarenCollege
Last active September 6, 2022 08:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save McLarenCollege/a419a045397bbabf36533e70d6cd5275 to your computer and use it in GitHub Desktop.
Save McLarenCollege/a419a045397bbabf36533e70d6cd5275 to your computer and use it in GitHub Desktop.
Book Discount with given Country

Book Discount With Given Country

Given a book with the structure below and the variable country, create a function that accepts the book object and a country name as a parameter,reduces the price of the book for that country by 40% and returns the book object. If there is no record for that country then the book object should not be modified.

let book = {
    author: 'Daniel Kahneman',
    title: 'Thinking, Fast And Slow',
    yearPublished: 2012,
    bestseller: true,
    pricePerCountry:
        {
            'Australia': {amount: 20.0, currency: 'AUD'},
            'India': {amount: 500, currency: 'INR'},
            'United States': {amount: 16.5, currency: 'USD'},
            'Canada' :{amount :19, currency :'CAD'}
        }
};
function reducePrice(bookObj, country){
// write your code here
}
console.log(JSON.stringify(reducePrice(book, "India")));
console.log(JSON.stringify(reducePrice(book, "United States")));
console.log(JSON.stringify(reducePrice(book, "Brazil")));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment