Find the error, help the person :)

<script type="text/javascript"> var a = new Array(5, 0, 2, 0, -3, 0); var b = new Array(); while (true) { var x = prompt("chislo", "0"); x = +x; if (x == 0) { break } for (var i = 0; i < a.length; i++) { if (a[i] == 0) { b[i] = "-"; continue; } b[i] = x / a[i]; } alert(a + " \n " x + " \n " + b); } </script> 

    2 answers 2

     alert(a+"\n"x+"\n"+b); // а надо alert(a+"\n"+x+"\n"+b); // и все равно алертать массивы - это странно. 

      What is this magic number?

       x = +x; 

      If you need to remove the sign:

       1. x = Math.abs(x) 2. x = ( x > 0 ) ? x : -x; 3. if ( x < 0 ) x = -x; 

      If you add 1, then:

       1. x++; 2. x += 1; 3. x = x + 1; 
      • This is a variation of parseFloat. - ling