Implementation of Snake in JS