JavaScript Code School "Closures" 任务中的打印问题
Trouble with printing in JavaScript Code School "Closures" task
Stack Overflow 和发帖的新手。刚开始接触 JavaScript,但我遇到了 CodeSchool 关闭问题。问题是:
现在针对特定障碍有效地计算了警报,Dev Girls 需要您存储报告的障碍位置,以便每个新警告都可以报告每个障碍的危险区域列表(他们正在努力遥控激光束鲨鱼,时间真的很紧迫)。
在你的警告制造者中使用闭包,找到一种方法将每个新位置存储在一个称为区域的数组中,然后在针对该特定障碍发出的每个警告中报告当前危险区域的完整列表。您的新提醒消息应如下所示:
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
我无法在新行上打印区域。我的代码不起作用:
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);
};
}
任何帮助都会很棒!
您可以使用数组 class 的 join
方法。
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.join('\n'));
zones.push(location + "/n");
如果你想要一个换行符,应该是反斜杠 character.Try
zones.push(location + "\n");
如果您将单个参数传递给 location
,那么之前的修复就足够了。要显示所有位置,您只需使用 Array.prototype.join() 在警报中加入它们(...)部分而不仅仅是 zones
.
zones.join('\n');
Stack Overflow 和发帖的新手。刚开始接触 JavaScript,但我遇到了 CodeSchool 关闭问题。问题是:
现在针对特定障碍有效地计算了警报,Dev Girls 需要您存储报告的障碍位置,以便每个新警告都可以报告每个障碍的危险区域列表(他们正在努力遥控激光束鲨鱼,时间真的很紧迫)。
在你的警告制造者中使用闭包,找到一种方法将每个新位置存储在一个称为区域的数组中,然后在针对该特定障碍发出的每个警告中报告当前危险区域的完整列表。您的新提醒消息应如下所示:
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
我无法在新行上打印区域。我的代码不起作用:
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);
};
}
任何帮助都会很棒!
您可以使用数组 class 的 join
方法。
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.join('\n'));
zones.push(location + "/n");
如果你想要一个换行符,应该是反斜杠 character.Try
zones.push(location + "\n");
如果您将单个参数传递给 location
,那么之前的修复就足够了。要显示所有位置,您只需使用 Array.prototype.join() 在警报中加入它们(...)部分而不仅仅是 zones
.
zones.join('\n');