JSFiddle - React, Tailwind, and code Playground

by brigand

JavaScript

class Category {
  constructor() {
    this.children = [];
    this.questions = [];
  }
}

class Question {
  constructor(name) {
    this.name = name;
    this.options = [];
  }

  toString() {
    return `> ${this.name}\n - ${this.options.join('\n - ')}`
  }
}


const foo = new Category();
const q = new Question('something');
q.options.push('foo', 'bar');
foo.questions.push(q);

console.log(foo.questions[0].toString())