javascript - 不知道为什么语法错误 ")"javascript

标签 javascript jquery function for-loop while-loop

我正在尝试创建一个运行 while 循环的函数。

它应该运行以下命令:

  1. 当循环中的数字是3的倍数时,将参数string1附加到div
  2. 当循环中的数字是5的倍数时,将参数string2附加到div
  3. 否则,在下面附加其他字符串

对于脚本标记中以“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/

相关文章:

javascript - 自定义函数(p,a,c,k,e,d)有什么用?

Javascript 不工作 - 2 个不同的 div 容器

javascript - js点击的过渡持续时间

javascript - 需要解释 : Cannot understand javascript returning a function

c - 主函数中的函数原型(prototype)?

javascript - js 数组解构的奇怪行为

javascript - 从jquery中的ul li获取多个检查值

javascript - Rails 技术在重定向后执行 javascript

jquery - 很多照片时滚动滞后

c - 将数据发送到 C 中的函数时数据表的更改