Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 12-01-2012, 01:59 AM   PM User | #1
123jo
New Coder

 
Join Date: Dec 2012
Posts: 10
Thanks: 2
Thanked 0 Times in 0 Posts
123jo is an unknown quantity at this point
Question JavaScript Program - Need your help!!

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

Last edited by 123jo; 12-02-2012 at 02:57 PM.. Reason: My code is modified below
123jo is offline   Reply With Quote
Old 12-01-2012, 06:09 AM   PM User | #2
felgall
Master Coder

 
felgall's Avatar
 
Join Date: Sep 2005
Location: Sydney, Australia
Posts: 5,465
Thanks: 0
Thanked 499 Times in 491 Posts
felgall is a jewel in the roughfelgall is a jewel in the roughfelgall is a jewel in the rough
JavaScript doesn't have a print function so for the print statements to work you'd need to create that function.
__________________
Stephen
Learn Modern JavaScript - http://javascriptexample.net/
Helping others to solve their computer problem at http://www.felgall.com/
felgall is offline   Reply With Quote
Users who have thanked felgall for this post:
123jo (12-01-2012)
Old 12-01-2012, 03:10 PM   PM User | #3
007julien
Regular Coder

 
Join Date: May 2012
Location: France
Posts: 115
Thanks: 0
Thanked 17 Times in 15 Posts
007julien is an unknown quantity at this point
Try simply this
Code:
<!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>
007julien is offline   Reply With Quote
Old 12-01-2012, 04:05 PM   PM User | #4
123jo
New Coder

 
Join Date: Dec 2012
Posts: 10
Thanks: 2
Thanked 0 Times in 0 Posts
123jo is an unknown quantity at this point
Thanks for your help guys.

Last edited by 123jo; 12-01-2012 at 09:11 PM..
123jo is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 04:12 AM.


Advertisement
Log in to turn off these ads.