JS solution for the range tracker problem