Implemented below mentioned changes :

1. Added a initialize method to initialize the cart.
2. Moved methods inside cart that belongs to cart and are previously present outside the class.
3. Added some methods to cart prototype.
4. Used ajax to fetch productJSON.
5. Break long methods to short and more readable methods.