可能有人请告诉我这是为什么不工作?我试着改变结构很多,但它似乎无所谓我放,当if else语句应用,它停止工作。除去if/else
之间的分号 - 正如评论所说的函数与if语句不工作?
alert("y is equal to zero)
加:
function wordSplit(){
var sentence = document.getElementById("two").value;
var userWords=sentence.split(" ");
while(t<userWords.length){
alert(userWords[t]);
t++
};
x = 0;
for (var x = 0; x < userWords.length; x++){
y = 0;
for (var y = 0; y < vocab.length; y++){
if (y<vocab.length) {
alert("y is less than vocab")
};
else if (vocab[y] == userWords[x]){
alert("y is equal to x")
};
else if(y<vocab.length) {
alert("y is less than vocab 2")
};
else if (y == vocab.length){
alert(" y is equal to vocab length")
};
else if (y == 0)
{
alert("y is equal to zero)
};
};
};
};
删除分号。语法是'if(){} else {}'。 – JJJ
if/else之间没有分号。 – adeneo
添加'“'零和) – David