[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.javascript

Found a bug in javascript see what it printout

JT

1/16/2016 11:15:00 PM

<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>
5 Answers

JT

1/16/2016 11:24:00 PM

0

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.

Michael Haufe (\"TNO\")

1/17/2016 12:05:00 AM

0

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

Darren Jackson

1/17/2016 7:43:00 PM

0

> 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-devel...

;^)

Thomas 'PointedEars' Lahn

1/18/2016 7:00:00 PM

0

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-devel...
>
> ;^)

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.... | SVN: <http://PointedEars.de...
Twitter: @PointedEars2 | ES Matrix: <http://PointedEars.de/es-...
Please do not cc me. / Bitte keine Kopien per E-Mail.

Darren Jackson

1/18/2016 7:20:00 PM

0

> "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.

:^)