Reputation: 1
This is the code:
var k ;
function getrandom()
{
k = Math.random()*2 ;
alert(k);
}
Hello I've searched a lot to see why this simple JS code is not working. I appreciate your help. Thank You.
Upvotes: 0
Views: 73
Reputation: 84150
I think you meant to do something like this:
function getrandom(max) {
alert(Math.round(Math.random()*max)) ;
}
getrandom(10);
Upvotes: 1
Reputation: 11270
Maybe you don't call this function?
Try this fiddle: http://jsfiddle.net/MRcmF/
It works!
Upvotes: 1
Reputation: 723688
Maybe you forgot to call it.
var k;
function getrandom()
{
k = Math.random() * 2;
alert(k);
}
getrandom();
Upvotes: 5
Reputation: 23169
If I execute your snippet and invoke getrandom()
it alerts a random number between 0 and 2. Is that not what the program is supposed to do?
Upvotes: 1