creating game mechanics in javascript (1)