Warning: session_start() [function.session-start]: open(/tmp/sess_rgm458skelsj0pjk1bdr4p9vm1, O_RDWR) failed: Disk quota exceeded (122) in /home/vipozico/forum.tutorials7.com/qa-include/qa-app-users.php on line 143
Write JS function that concatenates numbers as text
settingsAccountsettings
By using our mini forum, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy
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
...