+ 1

How can i write a function which add specific amount of whitespace to end of the string.

Eg. function("MyString",3) returns "MyString "

13th Aug 2017, 11:26 PM
oneCaptain
oneCaptain - avatar
1 Respuesta
+ 1
window.onload = function() { var p = document.getElementById("p-tag"); function addSpaces(str, spaces) { for(var i = 0; i < spaces; ++i) { str += "&nbsp;" } return str; } p.innerHTML = "*" + addSpaces("some text", 3) + "*"; }
14th Aug 2017, 12:52 AM
ChaoticDawg
ChaoticDawg - avatar