Hi

The following code is part of a program i have written:

for (var count = 1; count <= password.length-2; count = count + 1)
{
    document.write('*')

};

What i want is for the output of the above (which would be a number of characters the password is minus 2 shown in *) to not be written to the screen but to be added as a value to a variable.
Obviously document.write puts it on the screen. I want to be able to assign it to a variable, say 'code' and then i can use this elsewhere in my program.

Anyone know of a way.

Cheers

Edited 3 Years Ago by mike_2000_17: Fixed formatting

I haven't tested it out but you can try this am assuming this is what you are asking.

function getCode(password){
   var code="";
   for(var count=1; count<=password.length-2;count++){
      code+="*";
   }
return code;
}

You could then just call the function to assign the string to whatever. I think you could even print it straight.

document.write(getCode(theVarYouCalledPassword));

I repeat I haven't tested anything.

This question has already been answered. Start a new discussion instead.