Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #30212
| Newsgroups | comp.lang.javascript |
|---|---|
| Date | 2016-04-03 22:07 -0700 |
| References | (5 earlier) <9290ad47-7162-451e-9cb1-093492fffabb@googlegroups.com> <991dd634-d462-4535-972a-e8883d339685@googlegroups.com> <e6942d88-c355-4818-8bf3-2f165778d163@googlegroups.com> <20258829-fb27-4acd-b895-5d22c833eef4@googlegroups.com> <51e18650-48eb-4ef1-b81f-d1ac9e8c2d7a@googlegroups.com> |
| Message-ID | <7704f596-cb2a-481a-b215-66268a1592af@googlegroups.com> (permalink) |
| Subject | Re: Convoluted key events |
| From | jonas.thornvall@gmail.com |
Den måndag 4 april 2016 kl. 06:44:40 UTC+2 skrev jonas.t...@gmail.com:
> Den söndag 3 april 2016 kl. 22:59:34 UTC+2 skrev jonas.t...@gmail.com:
> > Den söndag 3 april 2016 kl. 22:49:09 UTC+2 skrev jonas.t...@gmail.com:
> > > Den söndag 3 april 2016 kl. 21:20:49 UTC+2 skrev Michael Haufe (TNO):
> > > > On Sunday, April 3, 2016 at 12:53:57 PM UTC-5, jonas.t...@gmail.com wrote:
> > > > > [...]
> > > >
> > > > For once in your life, use jshint.com on your code before asking a question.
> > >
> > > I did but apparently the language become so convoluted i really did not understand that the thing was a funtioncall looking at the code i still don't get it.
> > >
> > > interval = setInterval(function() { // loopcode here }, 0);
> > >
> > >
> > >
> > > Could you tell me what this code actually mean? I mean what is function() setInterval i do recognize as some timer one use, but i do not get what is actually returned?? what is the value that interval get 0 ms?
> > >
> > > To me the code make no sense, well the syntax i do not get it.
> > > I can see clearInterval reset the setInterval, is setInterval and clearinterval somehow the interval of the key listener?
> > > It isn't exactly obvious from the code that the interval even related to the keylistener?
> > >
> > > Lets say that i want to listen to the key a 1000 times should i call setInterval a 1000 times. It all seem convoluted and strange to me?
> > >
> > > I can explain waht i want todo in a single sentence and i can code it using basic in four lines.
> > > I want to run the RNG in a loop generating values in a buffer called binary or "whatever" when i press space or "any key" i want to print what is in buffer?
> > >
> > > Is it just my poor understanding of the language, or is there something incomprehensible convoluted that make it hard to express statements using the language builtin eventhandler.
> > >
> > > How many lines does it take todo what i describe above?
> > > Pseudocode
> > > myRandomVal(){
> > > interval=0;
> > > start.keyUP(A,interval)
> > > while(keyUP!=32){
> > > random=Math.floor(Math.random() * (max - min + 1)) + min;
> > > if(keyUP=32) {return random};
> > > }
> > > //clear.keyUP(A);
> > > stop.keyUP(A);
> > > }
> > >
> > > for (var i=1;i<1000;i++){
> > > out=myRandomVal();
> > > document.write(out);
> > > }
> > >
> > > I mean what is the reason to make the code incomprehensible "like my failed attempt above".
> > > Feel free to show me how it is done in Javascript, and if the code is cumbersome and convoluted please tell me why.
> >
> > And even my code seem convoluted naming the keyUP A but i can see it is useful if differentlisteners assigned to different keyranges.
>
> Yes i know sloppy
> Pseudocode
>
> function myRandomVal(){
> interval=0;
> random=0;
> start.keyUP(A,interval)
> while(keyUP(A)!=32){
> if(random==0) random=1 elseif (random==1) random=0;
>
> if(keyUP==32) {return random};
> }
> //clear.keyUP(A);
> stop.keyUP(A);
> }
>
> for (var i=1;i<1000;i++){
> out=myRandomVal();
> document.write(out);
> }
I reduced it a bit further
So what is wrong with this?
<script language="Javascript">
document.onkeyup = getKey;
function getKey() {
// If the users hits 'a', stop loopcode from running.
if(event.keyCode == 32){
window.clearInterval(interval);
document.esp.bin.value+=binary;
};
}
random=0;
interval = setInterval(function() {
// loopcode here
if(random==0){random=1} else if (random==1) {random=0;}
}, 0);
for(i=0;i<1000;i++){setInterval();}
</script>
//<HTML><BODY BGCOLOR=GRAY>
//<H1>EXTRASENSORY PERCEPTION TEST</H1>
//<table border=3>
//<tr bgcolor="white"><td colspan="3">
//<b>PICK THE IMAGE TO CONCENTRATE UPON, VISUALISE IT TO APPEAR IN EMPTY //SLOT
//</td><tr><td bgcolor=white colspan="3"><b>AND NOW REACH ZEN AND PRESS //SPACE TO GENERATE THE PICTURE</b></td></tr><tr>
//<td width=33%><input type="checkbox" name="checkbox" value="Milk"><br>
//<img src="happy.jpg" alt="happy" width="200" height="200"></td>
//<td width=33%><input type="checkbox" name="checkbox" value="Milk"><br>
//<img src="sad.jpg" alt="sad" width="200" height="200"></td>
//<td bgcolor=black></td>
//</tr></table>
//<FORM NAME="esp">
//GENERATED VALUES<br><TEXTAREA NAME="bin" COLS=100 ROWS=10></TEXTAREA>
//</FORM>
//</BODY></HTML>
Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Convoluted key events jonas.thornvall@gmail.com - 2016-04-03 09:15 -0700
Re: Convoluted key events jonas.thornvall@gmail.com - 2016-04-03 09:19 -0700
Re: Convoluted key events jonas.thornvall@gmail.com - 2016-04-03 09:32 -0700
Re: Convoluted key events jonas.thornvall@gmail.com - 2016-04-03 09:52 -0700
Re: Convoluted key events jonas.thornvall@gmail.com - 2016-04-03 10:16 -0700
Re: Convoluted key events jonas.thornvall@gmail.com - 2016-04-03 10:53 -0700
Re: Convoluted key events jonas.thornvall@gmail.com - 2016-04-03 11:17 -0700
Re: Convoluted key events "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2016-04-03 12:20 -0700
Re: Convoluted key events jonas.thornvall@gmail.com - 2016-04-03 13:49 -0700
Re: Convoluted key events jonas.thornvall@gmail.com - 2016-04-03 13:59 -0700
Re: Convoluted key events jonas.thornvall@gmail.com - 2016-04-03 21:44 -0700
Re: Convoluted key events jonas.thornvall@gmail.com - 2016-04-03 22:07 -0700
Re: Convoluted key events jonas.thornvall@gmail.com - 2016-04-04 03:00 -0700
Re: Convoluted key events jonas.thornvall@gmail.com - 2016-04-04 03:20 -0700
csiph-web