My javascript code is printing only one row. I need it to print 10 rows of 20 characters.

前端 未结 3 1550
误落风尘
误落风尘 2021-01-23 09:33

This is a coin flipping randomizer. I need to print out 10 rows and 20 columns. This is where I am stuck. My code seems to randomize correctly every time I click my button, it d

3条回答
  •  失恋的感觉
    2021-01-23 09:54

    The problem is you are replacing the entire results output each time you create a row with the new row. You need to append instead of replace. So change this:

    document.getElementById("results").innerHTML = arr + "
    ";

    To:

    document.getElementById("results").innerHTML += arr + "
    ";

    You also need to move the append of the result out of the inner for loop! If you leave the append within the for loop, you will see this behavior: http://jsfiddle.net/t1s93Lqz/3/

    JSFiddle: http://jsfiddle.net/t1s93Lqz/2/

提交回复
热议问题