0

How can I make a table?

How can I make a table in JavaScript that looks like this 🏳️🏳️🏳️🏳️X🏳️🏳️🏳️🏳️🏳️ 🏳️🏳️🏳️XXX🏳️🏳️🏳️🏳️ 🏳️🏳️XXXXX🏳️🏳️🏳️ 🏳️XXXXXXX🏳️🏳️ XXXXXXXXXX The white flags are spaces and I need the X to just be X. I just don’t understand pls help

22nd Oct 2018, 4:02 PM
Ezequiel
Ezequiel  - avatar
2 Respostas
+ 1
This is just an example, you can expand it to work without document.write calls, maybe use input and button to update the content dynamically. <script> var n = parseInt(prompt("Number of rows", "5")); document.write("Number of rows: " + n); document.write("<pre>"); pyramid(n); document.write("</pre>"); function pyramid(size) { var X = 1; // count of 'X' var n = size; var cols = size * 2; for(var row = size; row; --row) { var w = X * 2 - 1; for(var col = 1; col <= cols; ++col) { if(col < n || col >= n + w && (n + w < cols)) { document.write("&nbsp;"); } else { document.write("X"); } } --n; ++X; document.write("\n"); } return false; } </script>
23rd Oct 2018, 4:50 AM
Ipang
0
Try using a cycle - a 'for' for example
22nd Oct 2018, 5:42 PM
Chriptus13
Chriptus13 - avatar