Skip to content

Instantly share code, notes, and snippets.

@sriram15690
Created March 22, 2018 10:54
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 sriram15690/d10a0d695c7bae4bd74e5566ccbbd30e to your computer and use it in GitHub Desktop.
Save sriram15690/d10a0d695c7bae4bd74e5566ccbbd30e to your computer and use it in GitHub Desktop.
Use the below API to retrieve data using ajax & write two methods to do the following:
1.display products by category
2.display product data.
API: https://api.myjson.com/bins/nqap7
Inp: getProducts('Mobiles');
Op: ['iphone 7',"Samsung S9" ]
Inp: getProducts("xyz")
Op: Sorry No data found for category xyz.
Inp: getProductData('Mobiles', 'iphone 7');
Op: {
"name": "iphone 7",
"price": 7000,
"isAvailable": false
},
Inp: getProducts('Mobiles', "iPad")
Op: Sorry No data found for 'iPad' in 'Mobiles' category.
You can use console.log Or document.write for output.
function getProducts(category) {
// Parse the JSON
// Go to the the speicific category
// collect all product names & store it in an array
// return the array
}
function getProductData(category, productName) {
// Parse the JSON
// Go to the the speicific category
}
In the above methods, if you are not able to find the desired data, throw an error.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment