我正在尝试创建一个运行 while 循环的函数。
它应该运行以下命令:
- 当循环中的数字是3的倍数时,将参数string1附加到div
- 当循环中的数字是5的倍数时,将参数string2附加到div
- 否则,在下面附加其他字符串
对于脚本标记中以“for (x % 3 == 0) {”开头的行,我收到 Chrome 工具箱错误“Uncaught SyntaxError: Unexpected token )”。不明白为什么...
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<div id="output"></div>
<script src="https://code.jquery.com/jquery-2.1.1.js"></script>
<script>
var this_that = function(string1, string2) {
var x = 1
while (x <= 100) {
for (x % 3 == 0) {
$(#output).append(x, string1)
} else if (x % 5 == 0) {
$(#output).append(x, string2)
} else {
$(#output).append(x,'is not a multiple of 3 or 5')
}
x++
}
}
</script>
最佳答案
这里的 for
应该是 if
:
for (x % 3 == 0) {
应该是:
if (x % 3 == 0) {
关于javascript - 不知道为什么语法错误 ")"javascript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32065502/