specs
I am working on Linux Mint 14. I started on JavaScript recently and I tried to do some output formatting(printing random numbers, one per line) and as usual used \n
. But this does not seem to work.
On both the chromium web browser and mozilla firefox, only a space shows up.
code
<HTML>
<HEAD>
<TITLE> GENERATE RANDOM NUMBERS AND PRINT THEM </TITLE>
<BODY>
<div id='container'>
<button onclick='startPrinting()'>Generate random numbers </button>
</div>
</BODY>
</HTML>
</HEAD>
<script>
function startPrinting()
{
var b = document.getElementById('container');
//b.innerHTML += Math.floor(Math.random() * 1000);
b.innerHTML += '<br>The following are some random numbers.<br>';
for(var i =1;i<10;i++)
{
b.innerHTML += '\n';
b.innerHTML += i + '.' + Math.floor(Math.random() * 1000);
}
}
</script>
I tried <br>
and this worked well. But now I have many files where I have \n
.
So is there a way that I can tell the script to replace all occurences of \n
with <br>
?
If possible please give an answer that will ensure that i have to add only a few lines of code to my existing files.
(I am looking for something like #define
in C++)
please help me resolve this issue.