SOURCE

// 素数:除了1和它本身没有其他因数
function judgePrimeNum(num) {
    let str = ''
    if (!isNaN(num)) {
        if (num === 1) {
            str = '1既不是素数也不是合数'
        } else if (num === 2) {
            str = "2是素数"
        } else {
            for (let i = 2; i < num; i++) {
                if (num % i === 0) {
                    str = '不是素数'
                    break
                } else {
                    str = `${num}是素数`
                }
            }
        }
    } else {
        str = "非数字"
    }
    return str
}
const numStr = judgePrimeNum('1a')
console.log(numStr)
console 命令行工具 X clear

                    
>
console