function randomize() {
var ra = Math.floor(Math.random()*ar.length=4);
document.getElementById('es').innerHTML = ar[ra];
}
Is there a way to short this code even more than it is? The reason why is because I’m going to be using this code a lot in other projects and objects and I cannot just call it inside like this: randomize(); because I have diffrent arrays.
But you wanted to use it more without a function call:
And instead of
Math.floor, you can use~~for a microscopical faster diffrence.This saves some space and time if you are going to use it more. But if only one time, use the first example.