translating javascript code