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

for (var count = 1; count <= password.length-2; count = count + 1)


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.


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++){
return code;

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


I repeat I haven't tested anything.

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