vendredi 5 février 2016

How to get random variable's value in javascript

I am trying to generate random variables with some given format.

Although random varibles are generating, but how can I go ahead to assign and access those random variables ?

a = "a" + fun1(a="")
b = "b" + fun1(b="")
c = "c" + fun1(c="")

// How to assign values to these random variables
/*
  a_1 = "first random value";//suppose the value of a is a_1
  b_4 = "second random value";//suppose the value of b is b_4
  c_9 = "third random value";//suppose the value of c is c_9
*/
// How to get values of all random variables
/*
  alert(a_1)
  alert(b_4)
  alert(c_9)
*/
function fun1(str){
  return str + "_" + Math.floor(Math.random() * 10)
}

Thanks for your time.




Aucun commentaire:

Enregistrer un commentaire