JavaScript If / Else语句我无法使其正常工作

时间:2018-11-19 15:46:37

标签: javascript

基本上我想实现的是编写一个简单的if语句,如果变量“ additional”为N,它将运行代码的第一个块,但是每次仅运行第一个块:

for (i = 0; i < cars.length; i++) { 
    text += cars[i] + " ";
}

我做错了..?

let cars = ["Car1", "Car2", "Car3", "Car4"];
let text = "";
let additional = 4;
let i;
for (i = 0; i < cars.length; i++) { 
    text += cars[i] + " ";
}

if (additional = 4) {
    let cars = ["Car1", "Car2", "Car3", "Car4", "Case1"];
    console.log(text);
}
else {
    console.log("Error: Cars length is not the same.");
}

0 个答案:

没有答案