...

View Full Version : JavaScript Program - Need your help!!



123jo
12-01-2012, 02:59 AM
So I'm new at programming (just so you know) and I have a problem with my program. I want to create a function that print Pascal's triangle (centered). I have few problems with the spacing and general formats...

Thanks for your help in advance :)

felgall
12-01-2012, 07:09 AM
JavaScript doesn't have a print function so for the print statements to work you'd need to create that function.

007julien
12-01-2012, 04:10 PM
Try simply this

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<meta name="generator" content="PSPad editor, www.pspad.com">
<title></title>
<style type="text/css">
body{font-family:courier,monspace;text-align:center;}
p{margin:3px;}
</style>
</head>
<body>
<h1>Pascal's Triangle</h1>
<div id="pge"></div>
<script type="text/javascript">
function co(n,p) {
if ( n<p || n<0 || p<0 ) return 0;
if ( !p || !n) return 1;
return co(n-1,p-1)+co(n-1,p);
}
var N=0;
function nxtLgn(){var i,str='';
N++;
for (i=0;i<N;i++) str+=co(N,i)+'&nbsp;';
document.getElementById('pge').innerHTML+='<p>'+str+'</p>';
if (N<21) setTimeout(nxtLgn,10);
}
nxtLgn();
</script>
</body>
</html>

123jo
12-01-2012, 05:05 PM
Thanks for your help guys.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum