# Really short Javascript cube timer



## molarmanful (May 31, 2015)

You may have seen my other really short Javascript scrambler. Well, here's the really short Javascript timer! Source: https://gist.github.com/molarmanful/7b3f54efef4141959b4c. Any suggestions?


----------



## samuelqwe (May 31, 2015)

Woah! That is really short. Who can top that off?


----------



## cubernya (Jun 1, 2015)

Using an interval for a timer is not a good idea, as it gets inaccurate pretty quickly. Use the system's time instead (I'm sure this can be quite small as well)


----------



## molarmanful (Jun 1, 2015)

theZcuber said:


> Using an interval for a timer is not a good idea, as it gets inaccurate pretty quickly. Use the system's time instead (I'm sure this can be quite small as well)



I considered that approach; however, I decided to stick with intervals because they saved more bytes. Such is code golf...

EDIT: Okay, I decided to go with your approach. At least it's got accuracy.


----------



## 00 (Jun 1, 2015)

if you hold one key down and then press another, everything breaks.


----------



## molarmanful (Jun 1, 2015)

00 said:


> if you hold one key down and then press another, everything breaks.



Fixed. Also got byte count down to 316 bytes.


----------



## molarmanful (Jul 18, 2015)

Bump...

Got down to 261 bytes:

```
function z(){for(c=b=j=25,r=Math.random,s[i='innerHTML']='';j;c+b-5|c-m&&b-m?s[i]+="URFBLD"[j--,c=b,b=m]+" 2'"[0|r()*3]+" ":0)m=0|r()*6}z(),k=0,onkeyup=function(x){x.which^32||k?(clearInterval(T),z(),k=0):(S=new Date,k=1,T=setInterval("a[i]=(new Date-S)/1e3"))}
```

- Change all document.getElementById stuff to shorter variants.
- Use onkeyup.
- Change == to ^ and && to ||.
- Take out second setInterval parameter.

Any more suggestions for lowering byte count?


----------



## molarmanful (Jul 22, 2015)

More saves (258):

```
function z(){for(c=b=j=25,r=Math.random,s[i='innerHTML']='';j;c+b-5|c-m&&b-m?s[i]+="URFBLD"[j--,c=b,b=m]+" 2'"[0|r()*3]+" ":0)m=0|r()*6}z(),k=0,onkeyup=function(x){x.which^32||k?(clearInterval(T),z()):(S=new Date,T=setInterval("a[i]=(new Date-S)/1e3"));k=!k}
```
-Just merged k=0 and k=1 into k=!k.


----------



## molarmanful (Jul 22, 2015)

256 now:

```
function z(){for(c=b=j=25,r=Math.random,s[i='innerHTML']='';j;c+b-5|c-m&&b-m?s[i]+="URFBLD"[j--,c=b,b=m]+" 2'"[0|r()*3]+" ":0)m=0|r()*6}z(),k=onkeyup=function(x){x.which^32||k?(S=new Date,T=setInterval("a[i]=(new Date-S)/1e3")):(clearInterval(T),z());k=!k}
```

-Declare k with onkeyup.


----------



## kcl (Jul 22, 2015)

now this is mildly amusing


----------



## molarmanful (Jul 23, 2015)

kclejeune said:


> View attachment 5328
> 
> now this is mildly amusing



Haha lol

Wait, I'm pretty sure that's not supposed to happen...


----------

