Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/373.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
JavaScript-素数列表_Javascript_If Statement_For Loop_Selection_Primes - Fatal编程技术网

JavaScript-素数列表

JavaScript-素数列表,javascript,if-statement,for-loop,selection,primes,Javascript,If Statement,For Loop,Selection,Primes,我正在努力学习JavaScript。我用VB.NET创建了一个素数列表程序。当您单击“开始”按钮时,它将textbox.text拆分为textbox.text-1。就像这样: dim text as new textbox 0: text.text = textbox.text 1: text.text = text.text - 1 if text.text = "0" then listbox1.items.add(textbox1.text) textb

我正在努力学习JavaScript。我用VB.NET创建了一个素数列表程序。当您单击“开始”按钮时,它将textbox.text拆分为textbox.text-1。就像这样:

    dim text as new textbox
0:  text.text = textbox.text
1:  text.text = text.text - 1
    if text.text = "0" then
    listbox1.items.add(textbox1.text)
    textbox1.text = textbox1.text + 1
    goto 0
    else
    if (textbox1.text / text.text).contains(",") then
    goto 1
    end if
    end if
现在,我正试图用JavaScript实现这一点。我的JavaScript代码如下所示:

function okey(){
  var x=document.getElementById('mytext').value;
  var y=document.getElementById('mytext').value;
  looping: do {
    if (y=0){
      alert('Yup!');
    }
    else
    {
      var y=y-1;
      var s = x/y;
      if (s.indexOf(".") !== -1) 
      {
        continue looping;
      }
      else
      {
        alert('Sorry :(');
      }
   }
}
while(0);
我说,我正在学习JavaScript。我昨天开始的
注意:我想在select中添加它(比如listbox)。我该怎么做?
谢谢大家

if(s.indexOf(“,”)!=-1)

我想你可以用句号(“.”)代替(“,”)

试试这个

函数okey(){

}

var x=document.getElementById('TextBox1').value;
var y=document.getElementById('TextBox1').value;
var flag="not prime";
if (y<2){
    flag="None";
}
looping: 
{
    var y=y-1;
var s = x/y;
if (s.toString().indexOf('.') >0) 
  {
    flag="prime";
  }
     else
{
    flag="not prime";
}
while(y>2 && flag!="not prime");
alert (flag);