M
M
ma4t2019-02-28 09:25:15
css
ma4t, 2019-02-28 09:25:15

What is the correct way to write JS code in Pug?

.block
                - for (var x = 0; x < 13; x++)
                if x = 0
                    span Вася
                        .bottom-line
                else if x = 6
                    span Петя
                        .bottom-line
                else if x = 11
                    span Юра
                        .bottom-line
                else
                      span

This is the code in Pug that doesn't work
Hello, I'm trying to make a loop that outputs a span, the parent has flex and space-between
I need the 1st, middle and last blocks to receive text when the blocks are displayed, and the rest are displayed without text, which I write not So?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
ⓒⓢⓢ, 2019-02-28
@ma4t

https://codepen.io/anon/pen/wOKWra

V
Vladimir Proskurin, 2019-02-28
@Vlad_IT

I don't remember how you can use the js for loop in Pug (and I can't check it, because pug online doesn't work), but I usually use the built-in pug loops, for example

.block
    each _, x in Array(13)
        if x == 0
            span Вася
                .bottom-line
        else if x == 6
            span Петя
                .bottom-line
        else if x == 12
            span Юра
                .bottom-line
        else
              span

UPD: oh, you have an error in the indentation, after for, the entire body of the cycle should be to the right. Also, the last index is not 11, it is 12
- for (var x=0; x<13; x++)
  if x == 0
      span Вася
          .bottom-line
  else if x == 6
      span Петя
          .bottom-line
  else if x == 12
      span Юра
          .bottom-line
  else
        span

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question