xcislav — 2014-04-16T10:33:35-04:00 — #1
I'm shortening the code:
<input onload="t=0;" onkeypress="t?e=new Date():s=new Date();t=1" onblur="d=e.getTime()-s.getTime();c=this.value.length;this.value+=c/d">
<input onkeypress="t?e=new Date():s=new Date();t=1" onblur="d=e.getTime()-s.getTime();c=this.value.length;this.value+=c/d"><script>t=0;</script>
The working example is bloated with script tags.
The code before that included:
t==0s=new Date():e=new Date()
I was advised to exchange places s and e. And now I don't know what's simply "t" before ternary "?"
scallioxtx — 2014-04-16T14:49:27-04:00 — #2
t is the value of the variable t, which is set to 0 initially
Then when someone presses a key while that input is focused it will look at the value of t, which is 0 the first time, which will be interpreted as false, so s will be set, and then t is set to 1. Then if they press another key, t will be one, and e will be set.
So, first time s will be set, any time after that e will be set.
Looks like the script attempts to display the number of key strokes per second (but fails because it doesn't take into account that people can remove text and enter new test instead, which should also amount to the number of key strokes I'd say)
felgall — 2014-04-16T15:20:05-04:00 — #3
That shorter code is:
- harder to read
- harder to maintain