Reputation: 2170
Hello I am not very good at javascript, and I am trying to save the value returned from
(Math.random() + '') * 1000000000000000000 + '?'
Inside a cookie using: document.cookie
So far I have this:
document.cookie="rand="(Math.random() + '') * 1000000000000000000 + '?'";path=/";
But it is just storing (Math.random() + '') * 1000000000000000000 + '?' as a string and not actually using it to compute a value, can some please explain where I am going wrong?
Upvotes: 0
Views: 136
Reputation: 12018
Assign the value of your math operation to a variable and then append that into your cookie string. Be sure to use the + to concatenate it. It seems you forgot it in your example.
Upvotes: 0
Reputation: 51937
var TheNumber = Math.random() * 1000000000000000000;
document.cookie = "rand=" + TheNumber.toString() + '?";path=/"';
Upvotes: 4