Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

113
Views
For Loop within a function to add characters to a string doesn't return the characters added within the loop

I am trying to create an ascii type table to output to the console. One of the columns will have an input column header, a persons name. Since name length will vary, I wanted to create a dynamic way to build the table etc.

Here is a hypothetical goal:

+---------+---------+------------+
|  Round  |  Bruce  |  Computer  |
+---------+---------+------------+
|    1    | X       |            |
|    2    |         | X          |
|    3    | X       |            |
|    4    | X       |            |
|    5    |         | X          |
+---------+---------+------------+

In order to get the columns to line up etc, they'll need to be able to vary. Just starting, I wanted to create the horizontal 'border' and I tried the following:

let dasher = (nameLength) => {
    let temp = '----';
    for (let i = 0; i < nameLength; i++) {
        temp + '-';
    }
    return temp;
}

let hr = `+---------+` + dasher(playerName.length) + `+------------------+`;

However, I only get the 4 initial '-', but no additional '-'. The output is:

+---------+----+------------------+

But the desired output for the name Bruce, should be:

+---------+---------+------------------+

I am certain it has something to do with JS's asynchronous behaviours, just don't know how or how else to get what I am looking for

about 4 years ago · Santiago Gelvez
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!