Embedding a loop

Report a typo

You want to get a list of numbers from 1 to 10 using the following code:

val myDocument = document { }
myDocument.append {
    html { 
        body {
            for (i in 1..10) {
                div {
                    +i
                }
            }
        }
    }
}
println(myDocument.serialize())

What HTML code will you see in the console?

1)

<!DOCTYPE html>
<html>
  <body>
    <div>+1</div>
    <div>+2</div>
    <div>+3</div>
    <div>+4</div>
    <div>+5</div>
    <div>+6</div>
    <div>+7</div>
    <div>+8</div>
    <div>+9</div>
    <div>+10</div>
  </body>
</html>

2)

<!DOCTYPE html>
<html>
  <body>
    <div>2</div>
    <div>3</div>
    <div>4</div>
    <div>5</div>
    <div>6</div>
    <div>7</div>
    <div>8</div>
    <div>9</div>
    <div>10</div>
    <div>11</div>
  </body>
</html>

3)

<!DOCTYPE html>
<html>
  <body>
    <div>0</div>
    <div>1</div>
    <div>2</div>
    <div>3</div>
    <div>4</div>
    <div>5</div>
    <div>6</div>
    <div>7</div>
    <div>8</div>
    <div>9</div>
  </body>
</html>

4)

<!DOCTYPE html>
<html>
  <body>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
    <div></div>
  </body>
</html>

5)

<!DOCTYPE html>
<html>
  <body>
    <div>1</div>
    <div>2</div>
    <div>3</div>
    <div>4</div>
    <div>5</div>
    <div>6</div>
    <div>7</div>
    <div>8</div>
    <div>9</div>
    <div>10</div>
  </body>
</html>

You can run this code in the IDE and see the result.

Select one option from the list
___

Create a free account to access the full topic