The conditions of the task itself. The only thing that I can not do is to make the leftmost space in one line.
for (var i = '# # # #'; i.length < 17; i = i + ' ') { document.write(i + '<br>'); console.log("["+i+"]"); } The conditions of the task itself. The only thing that I can not do is to make the leftmost space in one line.
for (var i = '# # # #'; i.length < 17; i = i + ' ') { document.write(i + '<br>'); console.log("["+i+"]"); } If the length of the string i odd, then put a space:
for (var i = '# # # #'; i.length < 17; i = i + ' ') { document.write(i + '<br>' + ((i.length % 2 == 1) ? ' ' : '')); } //console.log("["+i+"]"); var inside = "[ ][#][ ][#][ ][#][ ]"; for (var i = 0; i < 8; i++) { var head = (i % 2 != 0)? "" : "[#]"; var tail = (i % 2 == 0)? "" : "[#]"; var line = head + inside + tail; document.write(line + '<br>'); //console.log("["+line+"]"); } Source: https://ru.stackoverflow.com/questions/792779/
All Articles