
November 12th, 2012, 09:24 PM
|
 |
Contributing User
|
|
|
|
It took me a minute to put it all together, but the code below should produce what your looking for and I also added a "if" condition; to remove the last trailing hyphen (comment that out / remove that, if you want to).
Code:
<script type="text/javascript">
var str = prompt('Input beginning number, ending number', '3,4');
var size = new Array();
var dimension = str.split(',');
var x = parseInt(dimension[0]);
var y = parseInt(dimension[1]);
var z = 0;
var max = 1;
for(i=0;i<y;i++) {
z++;
size.push((z*(z+1)/2));
}
for (iii=1;iii<y;iii++) {
max++;
for (ii=0;ii<max;ii++) {
document.write(size[ii]);
if (ii<(max-1)) {
document.write(" - ");
}
}
document.write("<br/>");
}
</script>
Last edited by web_loone08 : November 12th, 2012 at 09:30 PM.
|