Given a n*n matrix, assume 4*4 and it's all filled with red balls initially, upon the first click, the first ball changes to blue, a click on second ball changes it to blue, however a click on the third ball, changes it to blue and returns the first ball to red. Code the following in HTML,CSS,JS.