我在 while 循环中收到一个意外的标识符。如果我删除 while 循环,我不会收到意外的标识符,但在 javascript 中我不知道如何使此代码工作,因此我可以循环直到 j 小于 y div 2,同时在 while 循环中增加 yfunction Xploder(num,bits=1) { temp = BigInt(num) + BigInt(1) xnum = (temp * BigInt(Math.pow(2, bits)))-1n return xnum}var y = 3nvar j = 1009nfor (x=0; x<1; x++) { while ( (j < y//2) ) y=Xploder(y)}Thrown: y=Xploder(y) ^SyntaxError: Unexpected identifier> }我如何格式化我的代码,这样我就不会在 while 循环中或在 javascript 中得到意外的标识符,我如何正确编写上述代码。由下面的评论者回答。我正在从 python 切换到 javascript,只是没有注意到我通过不更改为 javascript 使用的正常划分来注释掉。感谢您的回答,我能够解决这个转换问题。再次感谢!
2 回答
![?](http://img1.sycdn.imooc.com/533e4d510001c2ad02000200-100-100.jpg)
杨魅力
TA贡献1811条经验 获得超6个赞
您正在评论 y 而不是将其分开。
function Xploder(num,bits=1) {
temp = BigInt(num) + BigInt(1)
xnum = (temp * BigInt(Math.pow(2, bits)))-1n
return xnum
}
var y = 3n
var j = 1009n
for (x=0; x<1; x++) {
while ( (j < y/2) )
y=Xploder(y)
}
![?](http://img1.sycdn.imooc.com/533e4cde000148e602000200-100-100.jpg)
人到中年有点甜
TA贡献1895条经验 获得超7个赞
双正斜杠是您标记评论开始的方式,因此:
for (x=0; x<1; x++) {
while ( (j < y//2) )
y=Xploder(y)
}
被解析为:
for (x=0; x<1; x++) {
while ( (j < y y=Xploder(y)
}
...解释了错误消息。
如果要分割,请使用单个 /
for (x=0; x<1; x++) {
while (j < y/2)
y=Xploder(y)
}
添加回答
举报
0/150
提交
取消