Jumping line before time

0
<script>

    var i = 0;

    while(i < 100){

        n = 1;
        resultado = n + i;

        if(0 === (i%10)){

            document.write(n + '-' + resultado + '<br>');

        }else{
        document.write(n + '-' + resultado + ' ');
        }


        i++;
    }
</script>

I'm typing this code for an exercise, and it's still part of what I want to do, but I've encountered a problem, it's giving the if command to skip the line before the time, it was only to be 1-10, but he does it in the 1-1, I hope you can understand, I'm sorry if I said badly, but I'm starting to study this area now, thanks!

    
asked by anonymous 16.06.2017 / 07:33

2 answers

0

As already told in the comments, the first iteration is already 0, so its the line break.

If you start at 1 and replace < 100 to:

16.06.2017 / 13:28
0

You can just change the if to 0 === ((i + 1)% 10) and keep the rest of your logic.

<script>

    var i = 0;

    while(i < 100){

        n = 1;
        resultado = n + i;

        if(0 === ((i+1)%10)){

            document.write(n + '-' + resultado + '<br>');

        }else{
        document.write(n + '-' + resultado + ' ');
        }


        i++;
    }
</script>
    
16.06.2017 / 13:38