Giter Club home page Giter Club logo

grocery_shopping's Introduction

I thought it would be cool to create something that delivers the ingredients for my favorite recipe to my apartment. Basically BlueApron but for a recipe of my choosing. I found Mathias Hansen's unofficial peapod API and decided to give it a try.

I'd never worked with node previously so I learned about npm and using it to install packages both locally and globally.

Running SpicySauagePasta.js will add all the ingredients needed for Kevin & Amanda's Spicy Sausage Pasta to my Peapod cart.

My biggest issue with this project was finding the right method to add each element in the array of ingredients to the peapod cart.

Method 1: a simple for loop Issue: The for loop ran faster than the "peapod API" was able to process. Any items the loop processed while waiting on the API to response were not added to the card.

Method 2: the setTimeout method -- I used this to create a recursive loop that would add an item every 2 seconds. This worked but having a set time creates it own problems. Issue: If the api took more than 2 seconds then the item would be skipped or if the api took more than 2 seconds then the program is slow for no reason.

Method 3: Callbacks! Instead of a for loop or a timed loop to cycle through the array of ingredients, I created two functions. One function adds items to the cart and the other increases the index on the ingredients array. Each function calls the other once it has finished running. When all the elements in the ingredient array after been added to the cart it stops. It took me a few tries to nail down the logic, but now it works great. ๐ŸŽ‰

grocery_shopping's People

Contributors

nyhasfun avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.