I'm getting the following error on browser console
Uncaught TypeError: rand.slice is not a function
JavaScript
var rand, date;
date = Date.now();
rand = Math.random() * Math.random();
rand = Math.floor(date * rand);
rand = rand.slice(-5);
document.getElementById("test").innerHTML = rand;
I'm not able to figure it out what's wrong with this code.
you can't directly slice a number.. you can convert to string first then slice
after
like this:
rand = rand.toString().slice(-5)
JavaScript Array slice() Method
JavaScript String slice() method
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With