Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #29268 > unrolled thread

Found a bug in javascript see what it printout

Started byjonas.thornvall@gmail.com
First post2016-01-16 15:14 -0800
Last post2016-01-18 11:19 -0800
Articles 6 — 4 participants

Back to article view | Back to comp.lang.javascript


Contents

  Found a bug in javascript see what it printout jonas.thornvall@gmail.com - 2016-01-16 15:14 -0800
    Re: Found a bug in javascript see what it printout jonas.thornvall@gmail.com - 2016-01-16 15:24 -0800
    Re: Found a bug in javascript see what it printout "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2016-01-16 16:05 -0800
    Re: Found a bug in javascript see what it printout "Chris M. Thomasson" <nospam@nospam.nospam> - 2016-01-17 11:42 -0800
      Re: Found a bug in javascript see what it printout Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-01-18 19:59 +0100
        Re: Found a bug in javascript see what it printout "Chris M. Thomasson" <nospam@nospam.nospam> - 2016-01-18 11:19 -0800

#29268 — Found a bug in javascript see what it printout

Fromjonas.thornvall@gmail.com
Date2016-01-16 15:14 -0800
SubjectFound a bug in javascript see what it printout
Message-ID<4ab38ff8-e97b-43cb-9077-b5ca6ee23ea1@googlegroups.com>
<script language="Javascript">

function factor_it(i){
prime=true;
sqroot=Math.floor(Math.sqrt(i));
for (j=2;j<sqroot;j++){ k=i/j; prime=!Number.isInteger(k); if (prime) {return prime}}
return prime;
}

function main(){
base=10;
outStr="";

//while (base==10) {
prime=false;
primeleg=false;
j=1;

while(j<base){

i=j;
i=i+base;
while (i<100){

// primeleg=factor_it(i);
 if(primeleg==true){break;}
 i=i+base;
}
j++;
outStr+="Base="+base+" counterval i = "+ i +" P primeleg ="+primeleg+"\n";
}

//base++;
//}
document.prima.out.value =outStr;
}
</script>
<!DOCTYPE html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
</head>

<body onload="main()" bgcolor="gold">
<form name="prima" action="" onsubmit="MAIN(); return false;">
<textarea name="out" cols=80 rows=80></textarea>
<textarea name="trash" cols=80 rows=80></textarea>
</form>
</body>
</html>

[toc] | [next] | [standalone]


#29269

Fromjonas.thornvall@gmail.com
Date2016-01-16 15:24 -0800
Message-ID<ab9028a9-0ee4-41ca-aefc-d01e0fb008fa@googlegroups.com>
In reply to#29268
Den söndag 17 januari 2016 kl. 00:15:02 UTC+1 skrev jonas.t...@gmail.com:
> <script language="Javascript">
> 
> function factor_it(i){
> prime=true;
> sqroot=Math.floor(Math.sqrt(i));
> for (j=2;j<sqroot;j++){ k=i/j; prime=!Number.isInteger(k); if (prime) {return prime}}
> return prime;
> }
> 
> function main(){
> base=10;
> outStr="";
> 
> //while (base==10) {
> prime=false;
> primeleg=false;
> j=1;
> 
> while(j<base){
> 
> i=j;
> i=i+base;
> while (i<100){
> 
> // primeleg=factor_it(i);
>  if(primeleg==true){break;}
>  i=i+base;
> }
> j++;
> outStr+="Base="+base+" counterval i = "+ i +" P primeleg ="+primeleg+"\n";
> }
> 
> //base++;
> //}
> document.prima.out.value =outStr;
> }
> </script>
> <!DOCTYPE html>
> <head>
> <meta http-equiv="content-type" content="text/html; charset=UTF-8">
> </head>
> 
> <body onload="main()" bgcolor="gold">
> <form name="prima" action="" onsubmit="MAIN(); return false;">
> <textarea name="out" cols=80 rows=80></textarea>
> <textarea name="trash" cols=80 rows=80></textarea>
> </form>
> </body>
> </html>

Bug resolved it was in brain double use of j in two loops.

[toc] | [prev] | [next] | [standalone]


#29271

From"Michael Haufe (TNO)" <tno@thenewobjective.com>
Date2016-01-16 16:05 -0800
Message-ID<6b6d21a1-efb8-44f9-a6f1-1a1d224c7f3f@googlegroups.com>
In reply to#29268
On Saturday, January 16, 2016 at 5:15:02 PM UTC-6, jonas.t...@gmail.com wrote:
> <script language="Javascript">
> 
> function factor_it(i){
> prime=true;
> sqroot=Math.floor(Math.sqrt(i));
> for (j=2;j<sqroot;j++){ k=i/j; prime=!Number.isInteger(k); if (prime) {return prime}}
> return prime;
> }
> 
> function main(){
> base=10;
> outStr="";
> 
> //while (base==10) {
> prime=false;
> primeleg=false;
> j=1;
> 
> while(j<base){
> 
> i=j;
> i=i+base;
> while (i<100){
> 
> // primeleg=factor_it(i);
>  if(primeleg==true){break;}
>  i=i+base;
> }
> j++;
> outStr+="Base="+base+" counterval i = "+ i +" P primeleg ="+primeleg+"\n";
> }
> 
> //base++;
> //}
> document.prima.out.value =outStr;
> }
> </script>
> <!DOCTYPE html>
> <head>
> <meta http-equiv="content-type" content="text/html; charset=UTF-8">
> </head>
> 
> <body onload="main()" bgcolor="gold">
> <form name="prima" action="" onsubmit="MAIN(); return false;">
> <textarea name="out" cols=80 rows=80></textarea>
> <textarea name="trash" cols=80 rows=80></textarea>
> </form>
> </body>
> </html>

Please created a properly formatted HTML document

Also correct the bugs in your code as raised in jshint.com

[toc] | [prev] | [next] | [standalone]


#29290

From"Chris M. Thomasson" <nospam@nospam.nospam>
Date2016-01-17 11:42 -0800
Message-ID<n7gqrt$frb$1@gioia.aioe.org>
In reply to#29268
> wrote in message 
> news:4ab38ff8-e97b-43cb-9077-b5ca6ee23ea1@googlegroups.com...

[...]

AFAICT, you really need to drill down on the (var) keyword...
_____________________
> function main(){
> base=10;
> outStr="";
> prime=false;
> primeleg=false;
> j=1;
> i=j;
}
_____________________

The above can be really dangerous!

http://scribu.net/blog/javascript-var-keyword-for-php-developers.html

;^) 

[toc] | [prev] | [next] | [standalone]


#29322

FromThomas 'PointedEars' Lahn <PointedEars@web.de>
Date2016-01-18 19:59 +0100
Message-ID<3610642.bVce6HhO8U@PointedEars.de>
In reply to#29290
Chris M. Thomasson wrote:

>> wrote in message
>> news:4ab38ff8-e97b-43cb-9077-b5ca6ee23ea1@googlegroups.com...

That is an attribution novel, not a proper attribution.  Not only is it too 
long, the name of the author is missing.  Also, the quotation level is 
wrong: the attribution line that *you* create is obviously not part of the 
quoted text, so it must not have a quotation character.  If your newsreader 
software (Windows Live Mail) cannot be configured properly, get a better 
one, such as KNode or Thunderbird/Icedove.

> [...]
> 
> AFAICT, you really need to drill down on the (var) keyword...
> _____________________
>> function main(){
>> base=10;
>> outStr="";
>> prime=false;
>> primeleg=false;
>> j=1;
>> i=j;
> }
> _____________________
> 
> The above can be really dangerous!
> 
> http://scribu.net/blog/javascript-var-keyword-for-php-developers.html
> 
> ;^)

1. There is no “Javascript” (see also my sig).

2. It is worse than described in that article.  The code above will throw a 
   ReferenceError exception in strict mode if base etc. do not resolve to
   the property of an object or have not been declared identifiers of
   variables.  Or, if they resolve to properties of an object, and those
   properties can or cannot be written to, anything can happen, depending on
   the object and the property.  (The latter is independent of the execution 
   mode.)  We have discussed this here many times before.

3. The From header field value of your posting violates RFC 5536 and 
   disregards netiquette.  While that may be acceptable to a source of
   trolls such as aioe.org, in Usenet it is not.

-- 
PointedEars
FAQ: <http://PointedEars.de/faq> | SVN: <http://PointedEars.de/wsvn/>
Twitter: @PointedEars2 | ES Matrix: <http://PointedEars.de/es-matrix>
Please do not cc me. / Bitte keine Kopien per E-Mail.

[toc] | [prev] | [next] | [standalone]


#29324

From"Chris M. Thomasson" <nospam@nospam.nospam>
Date2016-01-18 11:19 -0800
Message-ID<n7jdsa$145b$1@gioia.aioe.org>
In reply to#29322
> "Thomas 'PointedEars' Lahn"  wrote in message 
> news:3610642.bVce6HhO8U@PointedEars.de...

>> Chris M. Thomasson wrote:

>>> wrote in message
>>> news:4ab38ff8-e97b-43cb-9077-b5ca6ee23ea1@googlegroups.com...

> That is an attribution novel, not a proper attribution.  Not only is it 
> too
> long, the name of the author is missing.  Also, the quotation level is
> wrong: the attribution line that *you* create is obviously not part of the
> quoted text, so it must not have a quotation character.  If your 
> newsreader
> software (Windows Live Mail) cannot be configured properly, get a better
> one, such as KNode or Thunderbird/Icedove.

Yup. I apologize for the error/bug.

I used Thunderbird when I was on Linux a while back.

>> [...]

> 1. There is no “Javascript” (see also my sig).

> 2. It is worse than described in that article.  The code above will throw 
> a
>    ReferenceError exception in strict mode if base etc. do not resolve to
>    the property of an object or have not been declared identifiers of
>    variables.  Or, if they resolve to properties of an object, and those
>    properties can or cannot be written to, anything can happen, depending 
> on
>    the object and the property.  (The latter is independent of the 
> execution
>    mode.)  We have discussed this here many times before.

> 3. The From header field value of your posting violates RFC 5536 and
>    disregards netiquette.  While that may be acceptable to a source of
>    trolls such as aioe.org, in Usenet it is not.

Thank you for the heads up Thomas.

Windows Live Mail is pretty crappy and I have no proper excuse
for continuing to use it: Sorry!

I am downloading Thunderbird right now.

:^) 

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.javascript


csiph-web