Javascript Code Required

Status
Not open for further replies.

uplink600

Beta member
Messages
3
Good Afternoon.

I need help with some code please. I need to create a string of underscore characters and the string has to be the same length as another existing string or an element in an array.

So for example if I have the following......

A string 'hello world' or an array wordArray[0] = 'hello world'

....then I need to create a new string consisting of 11 underscore characters (one for each character) or however many characters are in the initial string or array element.

Hope you can help as I can't find any easy way to do this.

Thanks

BG
 
Code:
var s = "Hello world";
var s2 = "";

document.write(s + "(");
document.write(s.length + ")" + "<br/>");

for(var i = 0; i < s.length; i++)
{
	s2 += "_";
}
document.write(s2 + "(");
document.write(s2.length + ")" + "<br/>");

bleh
 
Code:
var str = 'Hello World!';
var str2 = '';

while (str2.length != str.length)
{
	str2 += '_';
}

document.write(str2);

Mine's shorter!

:p
 
Status
Not open for further replies.
Back
Top Bottom