Dynamically build a table

I want to create a table with n columns dynamically, where n is a counter value defined as

#let question-counter = counter("question")

So if I have two questions, I want the table to be

#let mainline() = align(center, table(
  columns: (2.6cm, 2.6cm),
  align: center,
  table.header(
    [Q1], [Q2], 
  ),
  [1.5], [1.5],
))

I have tried using a combination of question-counter.final().first() and

#(range(1, 2+1).map(i => "Q" + str(i))),

but I can’t seem to get a working solution.

I was able to figure it out (well through Gemini)

#context {
  // 1. Get the final value of the counter
  let count = question-counter.final(here()).first()
  
  // 2. Generate the table
  // We check if count > 0 to avoid errors if the document is empty
  if count > 0 {
    table(
      columns: count, // Create one column per question
      align: center + horizon,
      
      // 3. Generate Headers (Q1, Q2, etc.)
      ..range(1, count + 1).map(n => [*Q#n*]),
      
      // 4. Generate Empty Cells (bottom row)
      ..range(0, count).map(_ => [\ ]) 
    )
  }
}

I needed that context() there.