Skip to content

Instantly share code, notes, and snippets.

@irfansharif
Created September 27, 2015 08:18
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 irfansharif/3177fb23b212fd49fab2 to your computer and use it in GitHub Desktop.
Save irfansharif/3177fb23b212fd49fab2 to your computer and use it in GitHub Desktop.
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