Den söndag 3 april 2016 kl. 19:16:28 UTC+2 skrev jonas.t...@gmail.com:
> Den söndag 3 april 2016 kl. 18:52:55 UTC+2 skrev jonas.t...@gmail.com:
> > Den söndag 3 april 2016 kl. 18:32:38 UTC+2 skrev jonas.t...@gmail.com:
> > > Den söndag 3 april 2016 kl. 18:19:40 UTC+2 skrev jonas.t...@gmail.com:
> > > > Den söndag 3 april 2016 kl. 18:15:41 UTC+2 skrev jonas.t...@gmail..com:
> > > > > I try to grip and understand javascript key events, but i fail miserably.
> > > > > It may seem that i try to do a double RNG, but i want to generate a steady flow and take the value that is generated into myval at the time i press the key.
> > > > >
> > > > > However not even my function call to the random function work, a hint or an example, there certainly something i do not understand about the listeners function. I would like it to loop and wait for 1000 keypress generating 1000 values of 0 and 1.
> > > > >
> > > > > But not just 1000 random values, i want the function to be called in a loop generating values but i want the value generated as i press the key.
> > > > >
> > > > > I remember doing this in Basic it was very simple.
> > > >
> > > > <script>
> > > > document.onkeyup = getKey;
> > > >
> > > > function getKey() {
> > > > // If the users hits 'a', stop loopcode from running.
> > > > if(event.keyCode == 65){
> > > > window.clearInterval(interval);
> > > > document.write("test ",myval);
> > > > };
> > > > }
> > > >
> > > > function random (low, high) {
> > > > binary=Math.floor(Math.random() * (max - min + 1)) + min;
> > > > return binary;
> > > > }
> > > >
> > > > myval=0;
> > > > var interval = setInterval(function() {
> > > > // loopcode here
> > > > low=0;high=1;
> > > > myval=random(low,high);
> > > > }, 0);
> > > >
> > > > </script>
> > >
> > > And why " document.onkeyup = getKey;" isn't "document.onkeyup = getKey();" is also weird?
> >
> > Found some mismatch...
> > <script>
> > document.onkeyup = getKey;
> >
> > function getKey() {
> > // If the users hits 'a', stop loopcode from running.
> > if(event.keyCode == 65){
> > window.clearInterval(interval);
> > document.write("test ",myval);
> > };
> > }
> >
> > function random (min, max) {
> > binary=Math.floor(Math.random() * (max - min + 1)) + min;
> > return binary;
> > }
> >
> > myval=0;
> > for(x=0;x<1000;x++){
> > var interval = setInterval(function() {
> > // loopcode here
> > low=0;high=1;
> > myval=random(low,high);
> > }, 1);
> > }
>
> ?
> <script>
> document.onkeyup = getKey;
>
> function getKey() {
> // If the users hits 'a', stop loopcode from running.
> if(event.keyCode == 65){
> window.clearInterval(interval);
> document.esp.bin.value+=myval;
> // document.write("jonas");
> };
> }
>
> function random (min, max) {
> binary=Math.floor(Math.random() * (max - min + 1)) + min;
> return binary;
> }
>
> interval=1;
> myval=0;
> var interval = setInterval(function() {
> // loopcode here
> low=0;high=1;
> myval=random(low,high);
> }, 1);
>
>
>
> </script>
> <HTML><BODY>
I got something working in chrome, firefox complains event not defined.
But i do not think what come out is random?
<script>
document.onkeyup = getKey;
function getKey() {
// If the users hits 'a', stop loopcode from running.
if(event.keyCode == 65){
window.clearInterval(interval);
document.esp.bin.value+=binary.slice(-1);
// document.write("jonas");
};
}
interval=1;
min=0;max=1;
binary="";
for (x=0;x<1000;x++){
interval = setInterval(function() {
// loopcode here
binary+=Math.floor(Math.random() * (max - min + 1)) + min;
}, 0);
}
</script>
//<HTML><BODY>
//<FORM NAME="esp">
//GENERATED VALUES<br>
//<TEXTAREA NAME="bin" COLS=100 ROWS=10></TEXTAREA></FORM>
//</BODY></HTML>