Company logo
  • Empleos
  • Bootcamp
  • Acerca de nosotros
  • Para profesionales
    • Inicio
    • Empleos
    • Cursos y retos
    • Preguntas
    • Profesores
    • Bootcamp
  • Para empresas
    • Inicio
    • Nuestro proceso
    • Planes
    • Pruebas
    • Nómina
    • Blog
    • Calculadora

0

42
Vistas
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

7 months ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

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

7 months ago · Juan Pablo Isaza Denunciar

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 + '"')
7 months ago · Juan Pablo Isaza Denunciar

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 + '"')
}

7 months ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar empleo Planes Nuestro proceso Comercial
Legal
Términos y condiciones Política de privacidad
© 2023 PeakU Inc. All Rights Reserved.