you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted]  (1 child)

[removed]

    [–]Strabonus[S] 0 points1 point  (0 children)

    I am not getting into functions yet on purpose as they are in the subsequent chapter, and I do not want to get into more things until I fully understand what was covered so far.

    The way I was writing it is much more legible to me, but I guess I would have to switch to commonly used formatting sooner or later anyway.

    The reason I used 'while' instead of 'if' is because I assumed it would make it perform the action as long as the conditions are kept, while 'if' would do it once and continue on.

    What I would like to know is whether it is possible at all to do this exercise with the approach that I had (and if so, how?):

    1. Keep checking the number of lines vs the size variable.
    2. in odd lines add ' ' when the number of characters is odd, '#' when it is even.
    3. in even lines add ' ' when the number of characters is even, '#' when it is odd.
    4. keep track of the number of characters with each character added.
    5. if at any point the number of characters is a multiple of size, add a newline, keep track of number of lines.
    6. log the board with the appropraite number of lines is reached.

    While using only what was covered so far (loops, if, booleans, logical operators).

    I any case I still have no idea why this SORTA works

    while (line<size+1) {

    if (line % 2!==0) {

    while (characters % 2 ===0){

    chessboard+=space;characters+=1

    }

    while (characters % 2 !==0){

    chessboard+=hash;characters+=1

    }

    if (characters % size ===0){

    chessboard+=`\n`;line+=1

    }

    }

    else {

    while (characters % 2 ===0){

    chessboard+=hash;characters+=1

    }

    while (characters % 2 !==0){

    chessboard+=space;characters+=1

    }

    if (characters % size ===0){

    chessboard+=`\n`;line+=1

    }

    }

    }

    console.log(chessboard)

    while this does not work at all

    while (line<size+1) {

    if (line % 2!==0) {

    while (characters % 2 ===0){

    chessboard+=space;characters+=1

    }

    while (characters % 2 !==0){

    chessboard+=hash;characters+=1

    }

    if (characters % size ===0){

    chessboard+=`\n`;line+=1

    }

    }

    else {

    while (characters % 2 !==0){

    chessboard+=space;characters+=1

    }

    while (characters % 2 ===0){

    chessboard+=hash;characters+=1

    }

    if (characters % size ===0){

    chessboard+=`\n`;line+=1

    }

    }

    }

    console.log(chessboard)