The conditions of the task itself. The only thing that I can not do is to make the leftmost space in one line.

enter image description here

for (var i = '# # # #'; i.length < 17; i = i + ' ') { document.write(i + '<br>'); console.log("["+i+"]"); } 

    2 answers 2

    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) ? '&nbsp' : '')); } //console.log("["+i+"]"); 

    • ? '& nbsp': '' - since I am new to this business, you can explain what this part of the line does after the question mark - BraFik
    • ? - the condition operator, which selects one of the two; & nbsp - space character - teqwry

     var inside = "[&nbsp;&nbsp;][#][&nbsp;&nbsp;][#][&nbsp;&nbsp;][#][&nbsp;&nbsp;]"; 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+"]"); }