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

185
Views
Done / How to make a space printer in javascript
var arg = 5
var string = ' '
for (let i = 0; i < arg; i++) {
  console.log('"' + string + '"')
}

I expected the output is:

"     " \\ There are 5 spaces between the ""

But the output is:

" "
" "
" "
" "
" "

I am a newbie in javascript. Hope you will help me

about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

you can use method string.padEnd that fill string with blank space until parameter pass to the method

var arg = 5;
var string = ' ';
string = string.padEnd(arg)
console.log('"' + string + '"');

reference : https://developer.mozilla.org/fr/docs/Web/JavaScript/Reference/Global_Objects/String/padEnd

about 4 years ago · Juan Pablo Isaza Report

0

I don't think there is a way to console.log on the same line. You can do something like this

var arg = 5
var string = ' '
var final_string = ''
for (let i = 0; i < arg; i++)
  final_string = final_string + string
}
console.log('"' + final_string + '"')
about 4 years ago · Juan Pablo Isaza Report

0

I think you can use &nbsp; or \xa0 for printing spaces

var arg = 5
var string = '\xa0\xa0\xa0\xa0\xa0';
for (let i = 0; i < arg; i++) {
  console.log('"' + string + '"')
}

about 4 years ago · Juan Pablo Isaza Report
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!