Updated js of Question 3