Why do we say "trick ot treat"

Why Do We Say “Trick or Treat”?
It’s many kids’ favorite part of Halloween. There’s no feeling quite like waiting for a stranger to open their door so you can scream the words “Trick or treat!” But, why do we say it? What does it actually mean?
Where does the phrase trick-or-treat come from?
While some identify precursors to trick-or-treating in ancient Celtic customs, modern trick-or-treating is thought to be a custom borrowed from England, Scotland, and Ireland. These involve dressing in costume and singing a rhyme, doing a card trick, or telling a story in exchange for a sweet.
Some have traced the earliest print reference of the term trick or treat to 1927 in Canada. It appears that the practice didn’t really take hold in the US until the 1930s, where it wasn’t always well received. The demanding of a treat angered or puzzled some adults.