Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

135
Vistas
How to add text to value in console, without breaking it

so the code bellow would write ten numbers in the console. How could I add some text behind, lets say, number five? So it would write numbers like usual, but the number five would have also some text to it.

for (let x = 1; x < 11; x++) {
console.log(x);
}

about 4 years ago · Santiago Gelvez
3 Respuestas
Responde la pregunta

0

One more idea is to use switch statement (Could be more readable for a lot of cases "do something on 1" and "2" and "5" and so on).

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/switch

<script>
 for (let i = 1; i < 11; i++) {
   switch (i) {
     case 1:
       console.log("hello: " + i);
       break;
     case 5:
       console.log("hello: " + i);
       break;
     default:
       console.log(i);
   }
 }
</script>

default Optional A default clause; if provided, this clause is executed if the value of expression doesn't match any of the case clauses.

** out of topic: it is more common to use i inside for loop (i == index).

about 4 years ago · Santiago Gelvez Denunciar

0

Just use a ternary condition that checks if x is 5.

for (let x = 1; x < 11; x++) {
  console.log(x + (x == 5 ? ' text' : ''));
}

If you want the text before the number you can just move the expression like:

console.log((x == 5 ? 'text ' : '') + x)
about 4 years ago · Santiago Gelvez Denunciar

0

for(let x = 0; x < 11; x++) {
  if(x === 5) {
    console.log('number 5 and additional text');
  } else {
    console.log(x);
  }
}

if I understood your questioncorrectly, this should work

about 4 years ago · Santiago Gelvez Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda