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

195
Vistas
How to achieve multi-line output with formatting in JavaScript

I am experimenting with the following codepen.io trinket and trying to achieve multiline output with formatting for the JavaScript text that is returned in response to user-input.

For instance, if the user types "/engage" the following text is returned:

"Follow the white rabbit. I want this to be the second line"

The code is below. I would like the above text to:

a) be output on two separate lines with my being able to control the breaks between lines (like br in HTML) b) allow some basic formatting - specifically to add bold formatting to the word "rabbit". c) allow for changing the font size of "follow" to a larger font/or different style etc.

In short, I want to be able to add formatting (hyperlinks are also a key one) and can't find any direct documentation on this for useful reference. the \n works for line breaks, thank you @epascarello

I have tried various things but they all come up with errors.

RELEVANT CODE

submitForm.addEventListener("submit", function(e) {
    e.preventDefault();
    if (input.value === "/clear") {
        clearCommand();
    } else if (input.value === "/list" || input.value === "help") {
        listAllCommands();
    } else if (input.value === "/connect") {
        goProgress();
    } else if (input.value === "/engage") {
        matrixEffect();
        clearCommand();
        textArea.value = "Follow the white rabbit. I want this to be the second line"
    } else {
        textArea.value +=
            "\nERROR: Unknown command! Type 'help' for list of commands.";
        input.value = "";
    }
    textArea.scrollTop = textArea.scrollHeight;
});

CODEPEN ENTIRE SNIPPET

https://codepen.io/damyco/pen/oyewjR

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