Just joined Stack Overflow and looking for help with a JavaScript closure problem from CodeSchool. Here's the issue:
The Dev Girls need to keep track of reported obstacle locations in order to create a list of danger zones for each obstacle when issuing warnings about remote-controlled laser beam sharks (they're in a rush). Your task is to modify the warning maker function to store new locations in an array called zones and display all current danger zones in every warning message for that specific obstacle.
Beware! There have been obstacle sightings in the Cove today!number obstacle(s) spotted at the location! This is Alert #count today for obstacle danger. Current danger zones are: zone1
zone2
zone3
I'm struggling to get the zones printed on separate lines. My code attempt so far:
function warningMaker( obstacle ){
var count = 0;
var zones = [];
return function ( number, location ) {
count++;
zones.push(location + "/n");
alert("Beware! There have been "+obstacle+" sightings in the Cove today!\n" +
number+" "+obstacle+"(s) spotted at the "+location+"!\n" +
"This is Alert #"+count+" today for "+obstacle+" danger.\n" +
"Current danger zones are:\n" +
zones);
};
}
Any assistance would be greatly appreciated!