Write to a multi-line output in Javascript (document that opens in browser)

Asked

Viewed 79 times

-1

In javascript, I try to run programs in the browser that do calculations between numbers and generate a multi-line output, but it leaves everything in a single line when running the command. I tried to put ' n' at the end of each line, I tried to put ' ' and I tried to concatenate, but in the output of the browser, it’s all together in a single line. Someone would know how to solve?

<script>
     var n1 = window.prompt('Digite um numero: ')
     var n2 = window.prompt('Digite outro numero: ')

     num1 = parseFloat(n1)
     num2 = parseFloat(n2)
     soma = num1 + num2

     document.write(`A soma dos números foi igual a ${soma}`)
     document.write('Muito obrigado')
</script>

1 answer

1

Don’t forget that we are talking about HTML, so to skip a line just use the tag responsible for this, which is the tag <br />, being like this:

<script>
     var n1 = window.prompt('Digite um numero: ')
     var n2 = window.prompt('Digite outro numero: ')

     num1 = parseFloat(n1)
     num2 = parseFloat(n2)
     soma = num1 + num2

     document.write(`A soma dos números foi igual a ${soma}`)
     document.write('<br/>')
     document.write('Muito obrigado')
</script>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.