Finally get rid of <script> tags

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>

:ballot_box_with_check:

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 “?”

t is the value of the variable t, which is set to 0 initially


<script>t=0;</script>

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)

That shorter code is:

  1. harder to read
  2. harder to maintain
  3. a lot less efficient than if the JavaScript were being stored as a script instead of as text in the HTML.