1321941
1321941

Reputation: 2170

Javascript: Storing a cookie

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

Answers (2)

davidethell
davidethell

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

frenchie
frenchie

Reputation: 51937

var TheNumber = Math.random() * 1000000000000000000;

document.cookie = "rand=" + TheNumber.toString() + '?";path=/"';

Upvotes: 4

Related Questions