Created
September 27, 2015 08:18
-
-
Save irfansharif/3177fb23b212fd49fab2 to your computer and use it in GitHub Desktop.
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
var request = require('request'), | |
url = 'http://shopicruit.myshopify.com/products.json', | |
cost = 0 | |
function main() { | |
request(url, function(err, res, body) { | |
if(!err && res.statusCode == 200) { | |
var products = JSON.parse(body).products | |
products.forEach(function(product) { | |
if(isWallet(product) || isLamp(product)) { | |
buyAllVariants(product) | |
} | |
}) | |
checkout() | |
} | |
}) | |
function isWallet(product) { | |
return product.title.match(/wallet/i) != null | |
} | |
function isLamp (product) { | |
return product.title.match(/lamp/i) != null | |
} | |
function buyAllVariants(product) { | |
product.variants.forEach(function(variant) { | |
cost += parseFloat(variant.price) | |
}) | |
} | |
function checkout() { | |
console.log("Your bill amounts to " + cost + "!") | |
} | |
} | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment