【学习】js 输出一个正整数的所有质因数 如(90 = 2*2*3*5)

时间:2025-01-22 07:37:18
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title></title>
</head>
<body>
<button οnclick="commit()">确定</button>
</body>
<script>
  function commit() {
    var num = 90
    var a=''
    for (var i = 2; i <= num; i++) {
      if (num % i === 0) {
        num = num / i
          a= a + '' + i
        i = 1
      }
    }
    (a)
  }