function space(str, numspace)
{
output="";
for(i=0;i<str.length;++i)
{
output = numspace+ str;
}
for(i=0;i<str.length;++i)
{
output = output + numspace;
}
return output;
}
I am trying to get this function to add an equal amount of whitespace to both ends of the string. I am not allowed to use built-in functions so that explains why i'm doing this the long way.
The output I get with the code I have :
space("hello","--")
"--hello-----------"
The "-" signify spaces, so the amount of spaces on the left side of the string is correct, but the amount of spaces on the right side of the string is way to much. Anyone have any ideas why this is occuring?