<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>判断是否是质数</title> </head> <body> <script> const num = prompt('请输入数字:'); const flag = true; if (num < 1) { alert("请输入正确的数字!"); } else if (num == 1) { alert(num + "不是质数!"); } else { for (let i = 2; i < num; i++) { if (num % i == 0) { flag = false; break; } } if (flag == true) { alert(num + '是质数!'); } else { alert(num + '不是质数!'); } } </script> </body> </html>
标签:判断,质数,是否是,alert,flag,num,else From: https://www.cnblogs.com/DEYI-L/p/16861527.html