You are re-assigning the value of myVar on most lines, . Try removing any lines which re-initialise myVar (var myVar =) or introduce a new variable (var my =) . Look at the example (i–) again and see if you can make it apply it to your variable. I would recommend testing just one line of code at a time to see what works.