I have the following piece of code. For some reason the case statement that I don't want to execute (second for Case '2') is getting executing in addition to the correct one (Case '4'). After reading online it appears most ppl were able to resolve similar issue by adding a "break" statement. However it isn't working for me. Please advise.Output below is from my Browser
var chk = '4'
switch (chk) {
case '4':
var locations = [
["936001_STURGEON_BAY_MEYER", 44.8358, -87.3305, "LRA", 1],
["936087_SHADOW_LAKE", 45.2183, -88.5981, "LRA", 2],
["936136_PIG", 44.5925, -88.0808, "OMS", 3],
["936136_PIG", 44.5925, -88.0808, "OMS", 4]
];
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 15,
center: new google.maps.LatLng(locations[0][1], locations[0][2]),
mapTypeId: google.maps.MapTypeId.ROADMAP
});
var infowindow = new google.maps.InfoWindow({
maxWidth: 400000
});
var locations_all_cells1 = locations;
var marker, i;
for (i = 0; i < locations_all_cells1.length; i++) {
var type1 = locations_all_cells1[i][3];
switch (type1) {
case "OMS":
marker1 = new google.maps.Marker({
position: new google.maps.LatLng(locations_all_cells1[i][1], locations_all_cells1[i][2]),
map: map,
icon: 'http://maps.google.com/mapfiles/ms/icons/green-dot.png'
});
google.maps.event.addListener(marker1, 'click', (function(marker1, i) {
return function() {
infowindow.setContent(locations_all_cells1[i][0]);
infowindow.open(map, marker1);
}
})(marker1, i));
break;
case "LRA":
marker2 = new google.maps.Marker({
position: new google.maps.LatLng(locations_all_cells1[i][1], locations_all_cells1[i][2]),
map: map,
icon: 'http://maps.google.com/mapfiles/ms/icons/red-dot.png'
});
google.maps.event.addListener(marker2, 'click', (function(marker2, i) {
return function() {
infowindow.setContent(locations_all_cells1[i][0]);
infowindow.open(map, marker2);
}
})(marker2, i));
break;
case "UPSAVE":
marker3 = new google.maps.Marker({
position: new google.maps.LatLng(locations_all_cells1[i][1], locations_all_cells1[i][2]),
map: map,
icon: 'http://maps.google.com/mapfiles/ms/icons/yellow-dot.png'
});
google.maps.event.addListener(marker3, 'click', (function(marker3, i) {
return function() {
infowindow.setContent(locations_all_cells1[i][0]);
infowindow.open(map, marker3);
}
})(marker3, i));
}
}
break;
case '2':
var locations = [
["936001_STURGEON_BAY_MEYER", 44.8358, -87.3305, "LRA", 1],
["936087_SHADOW_LAKE", 45.2183, -88.5981, "LRA", 2],
["936136_PIG", 44.5925, -88.0808, "OMS", 3],
["936136_PIG", 44.5925, -88.0808, "OMS", 4]
];
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 15,
center: new google.maps.LatLng(locations[0][1], locations[0][2]),
mapTypeId: google.maps.MapTypeId.ROADMAP
});
var infowindow = new google.maps.InfoWindow({
maxWidth: 400000
});
var locations_all_cells = ;
var marker, i;
for (i = 0; i < locations_all_cells.length; i++) {
var type1 = locations_all_cells[i][3];
}
break;
default:
text = "Looking forward to the Weekend";
}
console.log(text);
Error Information