settingsAccountsettings
Menusettings

Q: Write JS function that concatenates numbers as text

+3 votes

I need to write JavaScript function that concatenates numbers as text:

  • Input: a string parameter, holding a number n
  • Output: the numbers 1…n, concatenated as single string
  • Example: "11" ->> "1234567891011"
asked in JavaScript category by user paulcabalit

1 Answer

+2 votes

Here's the code mate:

function numbers(inputNumber) {
    var str = '';
    for (var i = 1; i <= inputNumber; i++) {
        str = str + i;
    }
    console.log(str);
}

numbers('11');

 

answered by user andrew
edited by user golearnweb
...