function rot13(str) {
var yahoo = [];
for (var i = 0; i < str.length; i++) {
if (str.charCodeAt(i) > 64 && str.charCodeAt[i] < 91){continue;}{
var cnet = str.charCodeAt(i);
yahoo.push(cnet);
} else {
var j = str.charCodeAt(i);
yahoo.push(j);
}
}
var ugh = yahoo.toString();
return ugh;
}
rot13("SERR PBQR PNZC");
尝试在 for 循环内使用 if else 语句,但 else 语句存在一些问题(出现“语法错误:意外标记 else”)。现在的主要目标是尝试操作字符串字母字符,同时传递其他字符(即空格、感叹号等)。当然有一种更简单的方法可以做到这一点,但实际上只是想知道在循环内编写 if else 语句有什么问题以及哪里出错了。感谢帮助
最佳答案
在 if
之后有两个代码体:
if (str.charCodeAt(i) > 64 && str.charCodeAt[i] < 91)
{continue;} // actual body of the if
{ // just a random block of code
var cnet = str.charCodeAt(i);
yahoo.push(cnet);
}
第二个根本不是 if
的一部分,因为您只能获得 if
的一个代码块。这就是为什么 else
是“意外的”。
关于JavaScript - 循环内的 If 语句出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49465030/