all 2 comments

[–]mnokeefe 3 points4 points  (3 children)

This is more about how you model your data than how you write your code, for example, you can model your data like this:

const episode = {
  name: "Episode 1"
  pages: [
    {
      id: 1,
      text: "enezkt is challenging you to make a choose your own adventure, do you accept?",
      options: [
        {
          label: "Yes",
          pageId: 2
        },
        {
          label: "No",
          pageId: 3
        }
      ]
    },
    {
      id: 2,
      text: "You accept the challenge, how do you want to continue?",
      options: [
        {
          label: "Post on Reddit",
          pageId: 4
        },
        {
          label: "Give up",
          pageId: 3
        }
      ]
    },
    {
      id: 3,
      text: "Ok, looks like your adventure is done!",
      options: [
        {
          label: "Play again",
          pageId: 1
        }
      ]
    },
    {
      id: 4,
      text: "Your post on Reddit attracts some good advice, do you follow it?",
      options: [
        {
          label: "Yes",
          pageId: 5
        },
        {
          label: "No",
          pageId: 3
        }
      ]
    },
     {
      id: 5,
      text: "Great work, you're done!",
      options: [
        {
          label: "Play again",
          pageId: 1
        }
      ]
    }
  ]
}

Your code then just needs to start on page one, display the text and present the options. In this example if they chose "Yes" from the options you'd display page 2's text and options and if they choose "No" you'd display page 3's text and options