Last active
August 29, 2015 14:26
-
-
Save faddah/aefefa04284e24e68a41 to your computer and use it in GitHub Desktop.
a triangle of asterisks in a div done by plain JavaScript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <title> | |
| The Triangle of Asterisks! | |
| </title> | |
| </head> | |
| <body> | |
| <h1>The Triangle of Asterisks!</h1> | |
| <div id="asterisks"> | |
| </div> | |
| <script src="triangle-loop.js"></script> | |
| </body> | |
| </html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| var asterisk = '*'; | |
| var output = ""; | |
| var div = document.getElementById('asterisks'); | |
| var newtext; | |
| var p = document.createElement("p"); | |
| for(var i = 0; i < 10; i++) { | |
| output += asterisk; | |
| newtext = document.createTextNode(output); | |
| div.appendChild(p).appendChild(newtext); | |
| console.log(output + '\n'); | |
| } | |
| var asterisk = '*'; | |
| var output = ""; | |
| var div = document.getElementById('asterisks'); | |
| for(var i = 0; i < 10; i++) { | |
| output += asterisk; | |
| var p = document.createElement("p"); | |
| var newtext = document.createTextNode(output); | |
| div.appendChild(p).appendChild(newtext); | |
| console.log(output + '\n'); | |
| } | |
| */ | |
| var asterisk = '*'; | |
| var output = ""; | |
| var div = document.getElementById('asterisks'); | |
| for(var i = 0; i < 10; i++) { | |
| output += asterisk; | |
| var br = document.createElement("br"); | |
| var newtext = document.createTextNode(output); | |
| div.appendChild(newtext.appendChild(br)); | |
| console.log(output + '\n'); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment