Here is the javascript code I have done.
<!DOCTYPE html>
<html>
<head>
<title></title>
<body>
<script language = "javascript">
var names = new Array(4);
names[0] = prompt("Enter the students name");
names[1] = prompt("Enter the students name");
names[2] = prompt("Enter the students name");
names[3] = prompt("Enter the students name");
names[4] = prompt("Enter the students name");
document.write("Students name:" names[0] "Students name:" names[1] "Students
name:" names[2]
"Students name:" names[3] "Students name" names[4]);
names.sort();
document.write("Students name:" names[0] "Students name:" names[1] "Students
name:" names[2]
"Students name:" names[3] "Students name" names[4]);
</script>
</body>
</html>
The code outputs a response similar to this (array is from user prompt): Students name:AdamStudents name:brianStudents name:calebStudents name:aaronStudents name:brittStudents name:aaronStudents name:adamStudents name:brianStudents name:brittStudents name:caleb
Im trying to get the code to output like this
Students name:Adam
Students name:brian
Students name:caleb
Students name:britt
Students name:aaron
I tried using \n to do line breaks and
to do breaks but adding those made the code fail.
If anyone can share with me how to do the breaks it would be greatly appreciated.
CodePudding user response:
try to use <br>
tags like:
document.write("Students name:" names[0] "<br> Students name:" names[1] "<br> Students
name:" names[2]
"<br> Students name:" names[3] "<br> Students name" names[4]);
CodePudding user response:
Use <br>
document.write("Students name:" names[0] "<br>Students name:" names[1] "<br>Students
name:" names[2]
"<br>Students name:" names[3] "<br>Students name" names[4]);