Reply To: Generating a random confirmation code with function()

PennController for IBEX Forums Support Generating a random confirmation code with function() Reply To: Generating a random confirmation code with function()

#4231
Jeremy
Keymaster

Hi Sarah,

You’re almost there, but unfortunately you can’t refer to other PennController elements in a new* statement. And since you probably want to log the random code as well, I would store it in a Var element (whose .set command can also run javascript code):

let alphanum = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz"; 

PennController(
    newVar("ID", "")
        .settings.global()
        .set(v =>[...Array(8)].reduce(a=>a+alphanum.charAt(Math.floor(Math.random()*alphanum.length)),''))
    ,
    newText("code", "")
        .settings.text( getVar("ID") ) 
        .print()
)
.log("code", getVar("ID"))

I made the ID var global so you can add its value at the end of your results lines using .log.

NB: I reused your code but of course the trial defined here will be fully executed (and done) in an instant unless you add a wait command on an element of an appropriate type.

Jeremy