我是JavaScript的新手,因为我在CSS泡沫中损失了多年。我现在在大学里,我被要求准备一个允许7个俱乐部的申请书,将他们的团队姓名输入系统,在屏幕上显示每个俱乐部,然后将完整的列表列出,编号为1-7。
。我到目前为止有此代码:
document.write("<h3> Names 1-7</h3>");
// adds header to top of page
var football= new Array(7)
for (var count=0; count<7; count++) {
football [count] = windows.prompt ("Enter team name","");
}
{
document.write(football[count] + "<br />");
}
我接近拉出头发,什么都没有用。帮助?
我很长一段时间没有与JavaScript合作,但是我相信您的循环不正确,因此无法正常工作。应该是:
for (var count=0; count<7; count++) {
football [count] = window.prompt ("Enter team name","");
document.write(football[count] + "<br />");
}
我认为您在那里有错别字,使用window
不是windows
。
所以使用,
football [count] = window.prompt ("Enter team name","");
也将document.write
移入循环中。
document.write("<h3> Names 1-7</h3>");
// adds header to top of page
var football= new Array(7)
for (var count=0; count<7; count++) {
football [count] = window.prompt ("Enter team name","");
document.write(football[count] + "<br />");
}
window
不是 windows
,
ex。
var football= new Array(7);
for (var count=0; count<football.length; count++)
football [count] = window.prompt ("Enter team name " + (count+1) + " : ","");
document.write("<h3> Names 1-7</h3>");
for (var count=0; count<football.length; count++)
document.write ( football [count] + "<br>");