Code Monkey home page Code Monkey logo

apisproject's People

Contributors

gabrielperales avatar mcelearr avatar

Watchers

 avatar  avatar  avatar

apisproject's Issues

Declare your variables at the top of functions

It's a good idea to declare your variables at the top of functions. In many of your functions, you define them part-way down or throughout the function.

For example, here: https://github.com/The-Hip-Hip-Arrays/apisproject/blob/master/js/app.js#L75

Consider moving the variable declarations to the top. Even if the value is not immediately available at the start of the function, just define an empty variable (var randomHatsNumber;), and then reassign the value further down.

Interested to hear if you have a different perspective on this. You can read more about this in Maintainable JavaScript (page 39).

Michelle (FAC5)

Add second API to project

We really should at least attempt to add in a second API seen as that's the main point of the project!

refactor app.js

basic API call can be refactored into a function that then is reused.

Lack of meaningful tests

I understand that testing may have been difficult to wrap your heads around.

One of the reasons for this is that the way you have written your code makes it inherently difficult to test.

For example, see here. In these lines you are:

  • Parsing your response data
  • Mutating a global variable
  • Choosing a random element of an array
  • Some DOM manipulation
    That is quite a lot of different things going on. Ideally there would be a separation of concerns in your code.

This process is also repeated later on in your code. Repeated operations can be abstracted out to functions that can be tested by themselves. Similarly, instead of passing an anonymous function as your event handler, define a function separately that you can subsequently test.

How can I run this project?

Always a good idea to include run instructions in your README. Just a quick guide to cloning the repo, getting an API key (if you need one) and viewing the project will do.

Michelle (FAC5)

Global variables

You have quite a lot of global variables in app.js: https://github.com/The-Hip-Hip-Arrays/apisproject/blob/master/js/app.js. You are defining 9 variables at the top of the file.

Global variables are usually a bad idea, because they pollute the global namespace of your project. Relying too much on global variables can result in conflicts between various scripts on the same page. Read more about it here: http://stackoverflow.com/questions/2613310/ive-heard-global-variables-are-bad-what-alternative-solution-should-i-use.

Consider declaring them inside your functions and returning the values from there.

Michelle

API call for every picture change

You could separate the update image change function from the API call. API pulls 200 results. You could use all 200 results before making another call (and avoid annoying Zalando).

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.