1

I am trying to split my prompt values so that each word appears on a different line, but my code makes it so that the words are split by commas instead of to each line like I want it to. Thank you so much for helping!

<p div id="a"></div></p>

<script>

window.onload=function() {
var x=prompt("Enter Terms", "Terms")
document.getElementById("a").innerHTML=x.split(" ");
      for(var i=0; i < a.length; i++){
document.write(a[i]);
}

</script>

1 Answer 1

0

Use Array.prototype.join(), joins all elements of an array into a string using specified argument

window.onload = function() {
  var x = prompt("Enter Terms", "Terms");
  document.getElementById("a").innerHTML = x.split(" ").join('<br/>');
}
<div id="a"></div>

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.