Making use of functions in javascript code