0

Got stuck on Review error: Don’t make functions within a loop

Error can be found on:

    function initMap() {
    map = new google.maps.Map(document.getElementById('map'), {
        center: {
            lat: -34.60,
            lng: -58.38
        },
        zoom: 13,
        mapTypeControl: false
    });
    var largeInfowindow = new google.maps.InfoWindow();
    var bounds = new google.maps.LatLngBounds();
    for (var i = 0; i < locations.length; i++) {
        var position = locations[i].location;
        var title = locations[i].title;
        var marker = new google.maps.Marker({
            map: map,
            position: position,
            title: title,
            animation: google.maps.Animation.DROP,
            id: i
        });

        markers.push(marker);

        marker.addListener('click', function() {
            var self = this;
            populateInfoWindow(this, largeInfowindow);
            this.setAnimation(google.maps.Animation.BOUNCE);
            setTimeout(function() {
                self.setAnimation(null);
            }, 1400);
        });
        bounds.extend(markers[i].position);
    }

    map.fitBounds(bounds);
    viewModel = new AppViewModel();
    ko.applyBindings(viewModel);

}

Project can be found on: https://github.com/storchia/Neighborhood

Any help will be highly appreciated!!!

storchia
  • 1
  • 2
  • seems like you are making a function inside your for loop (in your add listener call)... just like your error message said. Move the function declaration outside the loop, it should fix it – Gab Jan 25 '18 at 02:29
  • I think you missed some close brackets at line 110 and 114 – Felix Jan 25 '18 at 02:31

0 Answers0