Created
March 22, 2018 10:54
-
-
Save sriram15690/d10a0d695c7bae4bd74e5566ccbbd30e to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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