Drawing a Christmas Tree Using Nested For Loops : For « Language Basics « JavaScript DHTML

Home
JavaScript DHTML
1.Ajax Layer
2.Data Type
3.Date Time
4.Development
5.Document
6.Dojo toolkit
7.Event
8.Event onMethod
9.Ext JS
10.Form Control
11.GUI Components
12.HTML
13.Javascript Collections
14.Javascript Objects
15.Javascript Properties
16.jQuery
17.Language Basics
18.Mochkit
19.Mootools
20.Node Operation
21.Object Oriented
22.Page Components
23.Rico
24.Scriptaculous
25.Security
26.SmartClient
27.Style Layout
28.Table
29.Utilities
30.Window Browser
31.YUI Library
JavaScript DHTML » Language Basics » For 
Drawing a Christmas Tree Using Nested For Loops
  
<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.Check the loop counter
3.For loop
4.Using a for..in Loop in JavaScript
5.A Demonstration of a Nested Loop
6.A for Loop Used to Count from 0 to 99
7.Using the label Statement
8.Using the continue and break Statements
9.Use of the for Statement
10.The break Statement
11.The continue Statement
12.Labeled Statements
13.Plain for loop
14.For loop with alert dialog
15.Declare for loop counter
16.Control the loop step
17.Use for loop to fill an array
18.Use for in loop to go through an array
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.