如果/ Else语句循环,javascript

时间:2016-07-31 05:29:17

标签: javascript arrays if-statement

嗨由于某种原因,控制台正在向我回复SyntaxError:其他令人意外的令牌,但我真的不知道这个问题,有人可以帮助我吗?

lineN = ["Times Square", "34th", "28th", "23rd", "Union Square", "8th"];
storeStops = [];

 function input ( start, stop ){

    if (lineN.indexOf(start)<lineN.indexOf(stop)){
        for (var fwd =lineN.indexOf(start) ; fwd < lineN.indexOf(stop) ;foward++);
        fwd.push(storeStops);
    }}
    else {for (var bwd =lineN.indexOf(start) ; bwd < lineN.indexOf(stop) ;bwd--);
        bwd.push(storeStops)
    };

1 个答案:

答案 0 :(得分:1)

这有效:

var lineN = ["Times Square", "34th", "28th", "23rd", "Union Square", "8th"];
var storeStops = [];

function input (start, stop) {
  if (lineN.indexOf(start) < lineN.indexOf(stop)) {
    for (var fwd =lineN.indexOf(start) ; fwd < lineN.indexOf(stop) ;foward++);
    fwd.push(storeStops);
  } else {
    for (var bwd =lineN.indexOf(start) ; bwd < lineN.indexOf(stop) ;bwd--);
    bwd.push(storeStops);
  }
}

您应该正确缩进代码,以便更容易捕获这些内容。你到处都缺少几个括号和括号。此外,在JavaScript中,;块之后没有if/else