• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
JavaScriptSource

JavaScriptSource

Search 5,000+ Free JavaScript Snippets

  • Home
  • Browse Snippets
    • Addon
    • Ajax
    • Buttons
    • Cookies
    • CSS
    • Featured
    • Forms
    • Games
    • Generators
    • Image Effects
    • Math Related
    • Miscellaneous
    • Multimedia
    • Navigation
    • Page Details
    • Passwords
    • Text Effects
    • Time & Date
    • User Details
Home / Miscellaneous / Xmas Tree Generator

Xmas Tree Generator

This script makes a random sized Christmas tree with random lights.

  1. Copy the coding into the HEAD of your HTML document
  2. Add the last code into the BODY of your HTML document
<!– STEP ONE: Paste this code into the HEAD of your HTML document  –>



<HEAD>



<!– This script and many more are available free online at –>

<!– The JavaScript Source!! http://javascriptsource.com –>

<!– Original:  Bryan Hood ([email protected]) –>

<!– Web Site:  http://www.bnhrobotics.com –>

<STYLE>

BLOCKQUOTE {font-weight:900; line-height:0.75em}

</STYLE>



</HEAD>
<!– STEP TWO: Copy this code into the BODY of your HTML document  –>



<BODY>



<!– This script and many more are available free online at –>

<!– The JavaScript Source!! http://javascriptsource.com –>

<!– Original:  Bryan Hood ([email protected]) –>

<!– Web Site:  http://www.bnhrobotics.com –>

<BLOCKQUOTE><FONT COLOR=#fafafa><CENTER>

    *<BR>

*  *  *<BR>

  *  *<BR>

<FONT COLOR=GREEN>

<SCRIPT LANGUAGE=”JavaScript”>

<!–

var Number=Math.random()*10+3;

var Length=Math.round(Number)

var width=1;

for (i=0; i<=Length; i++)

{

	for (x=0; x<=4; x++)

	{

		for (y=1; y<=width; y++)

		{

		var NewNumber=Math.random()*15;

		var Ornament=Math.round(NewNumber);

		if (Ornament<=1)

		{

		document.write(“</FONT><FONT COLOR=RED> ^</FONT><FONT COLOR=GREEN>”);

		}

		if (Ornament>=2){

		document.write(” ^”);

		}

		}

	document.write(“<BR>”);

	var width=width+1;

	}

var width=width-2;

}

//–>

</SCRIPT>

</CENTER></FONT></BLOCKQUOTE>



<p><center>

<font face=”arial, helvetica” size”-2″>Free JavaScripts provided<br>

by <a href=”https://javascriptsource.com”>The JavaScript Source</a></font>

</center><p>

Miscellaneous

Related Snippets:

  • Check if a string is a valid JSON
  • How To Import A JavaScript File In Another JavaScript File
  • Get all direct descendant elements that match a test
  • Detect Internet Explorer browser

Primary Sidebar

Popular Posts

Story Generator

IP Grabber – get a users IP address with JavaScript

Simple Calendar

Remove Ads

Astrological Calculator

Copyright © 2025 JavaScriptSource.com

  • About
  • Privacy Policy
  • FAQ
  • Jobs For Developers