added js to prob 6
refactored js problem 2