jeudi 29 janvier 2015

Trouble with printing in JavaScript Code School "Closures" task


New to Stack Overflow and posting. Just started getting into JavaScript and I'm stuck on a CodeSchool closure problem. The problem is:


Now that the alerts are effectively counted for a particular obstacle, the Dev Girls need you to store the reported obstacle locations so that a list of danger zones for each obstacle can be reported with each new warning (they are working on the remote-controlled laser beam sharks and are really pressed for time).


Employing closure in your warning maker, find a way to store each new location in an array called zones and then report the entire list of current danger zones in every warning that goes out for that particular obstacle. Your new alert message should be as follows:



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 having trouble getting the zones printed out on new lines. My code that won't work:



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 help would be great!





Aucun commentaire:

Enregistrer un commentaire