用于循环程序的java脚本,卡住了

时间:2016-11-02 13:51:59

标签: javascript node.js command-line

嗨,所以我以前从来没有做过JS,我很难弄清楚代码应该放在'???????????空间。如果有人可以帮助我,我将不胜感激。 (也在命令行上打开文件挣扎。我安装了nodejs,我试过.load'filename.js',但它知道.load)

for(var i=0; i<5; i++){ 
    fleet[i] = new Taxi(i);
}

for(var i=0; i<fleet.length; i++){
    print("Taxi with badge number " + fleet[i].badgeNumber + " is " + fleet[i].color);
}

??????????????? = "White";

for(var i=0; i<fleet.length; i++){
    print("Taxi with badge number " + fleet[i].badgeNumber + " is " + fleet[i].color);
    fleet[i].blowHorn()
}

这是所需的输出:

>>> load("assignment.js")
Taxi    with    badge   number  0   is  yellow
Taxi    with    badge   number  1   is  yellow
Taxi    with    badge   number  2   is  yellow
Taxi    with    badge   number  3   is  yellow
Taxi    with    badge   number  4   is  yellow
Taxi    with    badge   number  0   is  White
Beep!
Taxi    with    badge   number  1   is  White
Beep!
Taxi    with    badge   number  2   is  White
Beep!
Taxi    with    badge   number  3   is  White
Beep!
Taxi    with    badge   number  4   is  White
Beep!

1 个答案:

答案 0 :(得分:0)

您可以替换以下行

??????????????? = "White";

fleet.map((itm) => itm.color = "white");