Drawing a Christmas Tree Using Nested For Loops : For : Language Basics : JavaScript DHTML examples (example source code) Organized by topic

JavaScript DHTML
C++
PHP
JavaScript DHTML Home »  Language Basics   » [  For  ]   
 



Drawing a Christmas Tree Using Nested For Loops

Please note that some example is only working under IE or Firefox.

/*

Learn How to Program Using Any Web Browser
by Harold Davis 

Apress CopyRight 2004

ISBN: 1590591135
*/
<HTML>
<BODY>
<CENTER>
<SCRIPT
   var width=1
   for (i=0; i <= ; i++
   
      for (x=0; x<=4; x++
      
         for (y=1; y<=width; y++
         
            var Number=Math.random()*10
            var Ornament=Math.round(Number)
            if (Ornament<=1
            
               document.write("O")
            
            if (Ornament>=2
            
               document.write(" X")
            
         
         document.write("<BR>")
         width=width+1
      
      width=width-2
   
</SCRIPT>
</CENTER>
</BODY>
</HTML>
           
       
Related examples in the same category
1.  For loop for lines
2.  For loop
3.  Using a for..in Loop in JavaScript
4.  A Demonstration of a Nested Loop
5.  A for Loop Used to Count from 0 to 99
6.  Using the label Statement
7.  Using the continue and break Statements
8.  Use of the for Statement
9.  The break Statement
10.  The continue Statement
11.  Labeled Statements
12.  Plain for loop
13.  For loop with alert dialog








Home| Contact Us
Copyright 2003 - 04 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.