if(R.cells.length == cell) { if (count == 4){ .... count = 0; } if(count == 0){ count++; .... } } else if(count == 1){ count++; .... } и т.д.