I am having difficulty adding info windows to the markers on this google map. I have tried different methods but I think I am adding the code to the wrong place or calling the wrong variables. Can anyone help me out? thanks!
var beaches = [
    ['Bondi Beach', -33.890542, 151.274856, 1],
    ['Coogee Beach', -33.923036, 151.259052, 1],
    ['Cronulla Beach', -34.028249, 151.157507, 2],
    ['Manly Beach', -33.800101, 151.287478, 2],
    ['Maroubra Beach', -33.950198, 151.259302, 2]
];
var map = new google.maps.Map(document.getElementById('map'), {
    zoom: 10,
    center: new google.maps.LatLng(-33.88, 151.28),
    mapTypeId: google.maps.MapTypeId.ROADMAP
});
var infowindow = new google.maps.InfoWindow();
var markers = [];
var i, newMarker;
for (i = 0; i < beaches.length; i++) {
    newMarker = new google.maps.Marker({
        position: new google.maps.LatLng(beaches[i][1], beaches[i][2]),
        map: map,
        title: beaches[i][0]
    });
    newMarker.category = beaches[i][3];
    newMarker.setVisible(false);
    markers.push(newMarker);
}
function displayMarkers(category) {
    var i;
    for (i = 0; i < markers.length; i++) {
        if (markers[i].category === category) {
            markers[i].setVisible(true);
        } else {
            markers[i].setVisible(false);
        }
    }
}
google.maps.event.addListener(markers, 'click', (function (markers, i) {
    return function () {
        infowindow.setContent(beaches[i][0]);
        infowindow.open(map, markers);
    }
})(markers, i));
 
    