溫溫醬
2021-11-18 09:34:18
我在 while 循環(huán)中收到一個意外的標(biāo)識符。如果我刪除 while 循環(huán),我不會收到意外的標(biāo)識符,但在 javascript 中我不知道如何使此代碼工作,因此我可以循環(huán)直到 j 小于 y div 2,同時在 while 循環(huán)中增加 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 循環(huán)中或在 javascript 中得到意外的標(biāo)識符,我如何正確編寫上述代碼。由下面的評論者回答。我正在從 python 切換到 javascript,只是沒有注意到我通過不更改為 javascript 使用的正常劃分來注釋掉。感謝您的回答,我能夠解決這個轉(zhuǎn)換問題。再次感謝!
2 回答

楊魅力
TA貢獻1811條經(jīng)驗 獲得超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)
}

人到中年有點甜
TA貢獻1895條經(jīng)驗 獲得超7個贊
雙正斜杠是您標(biāo)記評論開始的方式,因此:
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
提交
取消