So I'm tasked with making program that can tell whether a number is prime or not. I want to solve this problem using a multiple if-statement. The one that I came up with is awkward. So i just want some feedback on how to make it better.:

所以我的任务是制作可以判断数字是否为素数的程序。我想使用多个if语句来解决这个问题。我提出的那个很尴尬。所以我只想要一些关于如何让它变得更好的反馈:

function primenumber(num) {
    if (num / num === 1 && num % 2 !== = 0 || num % 3 !== = 0 | num % 5 !== = 0 | num % 7 !== = 0) {
        return true;
    } else {
        return false
    }
}

I figured these numbers are the lowest common denominators. So a number is prime if these numbers don't divide evenly into it. Any feedback is greatly appreciated. Keep in mind that I am new to Javascript.

我认为这些数字是最低的共同点。因此,如果这些数字不均匀分配,则数字为素数。任何反馈都非常感谢。请记住,我是Javascript的新手。

1 个解决方案

#1


0

I figured it out:

我想到了:

If((num === 1) || (num === 2) || (num === 3) || (num === 5) || (num     === 7))
{ return true;
}

If((num%2===0) || (num%3===0) || (num%5===0) || (num%7===0)){
return false;}
}
return true; 
}

It may not be the most sophisticated coding but it's mine and it works perfectly.. at least according to coderbyte

它可能不是最复杂的编码,但它是我的,它完美地工作..至少根据coderbyte

更多相关文章

  1. typeescript:在数字上使用parseInt()时出错
  2. 剑指offer python版 数组中只出现一次的两个数字
  3. 如何在python 3中将单词转换为数字(自己的键和值)?
  4. 你怎么检查python字符串是否只包含数字?
  5. python - pandas或者sklearn中如何将字符形式的标签数字化
  6. 三个猜数字游戏代码(Python)
  7. 正则将长数字转为英式写法(从后向前3个数字一个逗号)
  8. 关于mysql对字符串的数字的排序
  9. sqlserver2008r2查找非中文字母数字出现的第一个位置

随机推荐

  1. android studio AndroidManifest.xml命名
  2. 关于Android 如何配置测试类
  3. 编译代码报出Android library projects c
  4. android WARNING: Application does not
  5. Android 关于WebView的相关属性
  6. 解决Eclipse3.6中Android 代码自动补全卡
  7. [Android] Android 使用 Greendao 操作 d
  8. Android(安卓)Sqlite 相关汇总
  9. Android实现自定义的 时间日期 控件
  10. 模仿天天动听的seekbar