How can i write a function which add specific amount of whitespace to end of the string. | Sololearn: Learn to code for FREE!
Новый курс! Каждый программист должен знать генеративный ИИ!
Попробуйте бесплатный урок
+ 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 ответ
+ 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