PageSourceSearch

https://longreads.com/wp-content/plugins/longreads-quiz/quiz.js?ver=1.0

js longreads.com collected 2026-09-24 08:27:44 UTC 30,220 bytes, 409 lines download raw bytes

1/**
2 * Longreads Reader Quiz
3 *
4 * A personality-style quiz that matches readers to one of four archetypes
5 * (Humanist, Flaneur, Archivist, Naturalist) based on seven questions.
6 * Each answer increments a category score; the highest score wins.
7 * Question 4 (index 3) doubles as a tiebreaker when categories are tied.
8 * Results include 3 randomly selected story recommendations per archetype.
9 * A ?result=category URL parameter allows direct linking to results.
10 */
11(function () {
12
13  // Exit quietly if quiz HTML is not on this page
14  if ( !document.getElementById( 'lr-quiz-screen' ) ) return;
15
16  // === DATA ===
17
18  // Seven questions, each with 4 answers mapped to reader categories
19  var questions = [
20    {
21      question: "When do you usually read?",
22      answers: [
23        { text: "On my commute", category: "flaneur" },
24        { text: "Weekend mornings with coffee", category: "humanist" },
25        { text: "On breaks, ideally outside", category: "naturalist" },
26        { text: "Whenever I fall down an internet rabbit hole", category: "archivist" }
27      ]
28    },
29    {
30      question: "Which headline makes you click immediately?",
31      answers: [
32        { text: "A whistleblower. A cover-up. A paper trail.", category: "archivist" },
33        { text: "\u201cI didn\u2019t expect to cry, but I did.\u201d", category: "humanist" },
34        { text: "The hidden, fascinating world of [obscure thing]", category: "flaneur" },
35        { text: "A scorched land. A sudden bloom. A new hope.", category: "naturalist" }
36      ]
37    },
38    {
39      question: "After finishing a great piece, you\u2026",
40      answers: [
41        { text: "Immediately send it to three people", category: "archivist" },
42        { text: "Reflect in a journal entry or a post online", category: "humanist" },
43        { text: "Look up everything else the writer has ever written", category: "flaneur" },
44        { text: "Search for traces of the topic in the world around me", category: "naturalist" }
45      ]
46    },
47    {
48      question: "A documentary just started. You\u2019re not going anywhere. It\u2019s about:",
49      answers: [
50        { text: "A sprawling institutional cover-up", category: "archivist" },
51        { text: "An artist, musician, or filmmaker", category: "flaneur" },
52        { text: "An everyday person who ignited a massive change", category: "humanist" },
53        { text: "An ecosystem, a species, a landscape", category: "naturalist" }
54      ]
55    },
56    {
57      question: "You\u2019re at a party. You\u2019re most likely to be found\u2026",
58      answers: [
59        { text: "In a heated conversation about the news", category: "archivist" },
60        { text: "In a deep one-on-one conversation", category: "humanist" },
61        { text: "Asking the host about the art on their walls", category: "flaneur" },
62        { text: "Chatting in the garden about my last hike", category: "naturalist" }
63      ]
64    },
65    {
66      question: "Your ideal Sunday afternoon looks like:",
67      answers: [
68        { text: "Catching up on all my RSS feeds", category: "archivist" },
69        { text: "A long phone call with someone I miss", category: "humanist" },
70        { text: "A museum, a record store, somewhere with things to look at", category: "flaneur" },
71        { text: "Outside, away from screens", category: "naturalist" }
72      ]
73    },
74    {
75      question: "What you really want from a longread is\u2026",
76      answers: [
77        { text: "To understand something I didn\u2019t before", category: "naturalist" },
78        { text: "To feel less alone", category: "humanist" },
79        { text: "To be surprised, delighted, or unsettled", category: "flaneur" },
80        { text: "To ignite my curiosity and creative impulse", category: "archivist" }
81      ]
82    }
83  ];
84
85  // Four reader archetypes, each with a label, description, and story pool
86  var results = {
87    humanist: {
88      label: "The Humanist",
89      description: "You\u2019re drawn to the particular: one mother\u2019s grief, one man's search for belonging, one stranger who changed everything. The stories that stay with you are the ones that make you feel less alone. You read to feel and to be seen.",
90      stories: [
91        { title: "35 and 1", author: "Maria Zorn", excerpt: "A brother lost, a son born, and the strange arithmetic of love.", url: "https://longreads.com/2026/02/24/motherhood-grief-loss/", image: "https://longreads.com/w
91p-content/uploads/2026/02/35-and-1-balloons.png" },
92        { title: "Tom Cat", author: "Jennifer Thuy Vi Nguyen", excerpt: "On duality, detachment, and life and death decisions.", url: "https://longreads.com/2025/11/06/identity-duality-deluge-detachment/", image: "https://longreads.com/wp-content/uploads/2025/11/TomCat_F.png" },
93        { title: "Beloved Bother", author: "Hannah Engler", excerpt: "A typo in my great-uncle\u2019s obituary held the key to understanding him.", url: "https://longreads.com/2025/08/07/1970s-fashion-designer-ronald-kolodzie/", image: "https://longreads.com/wp-content/uploads/2025/08/Beloved-Bother-A.jpg" },
94        { title: "Thank You For Finding Me", author: "Lisa Bubert", excerpt: "As a teenager, I met a stranger who changed the course of my life. Twenty years later, I went looking for him.", url: "https://longreads.com/2025/07/24/thank-you-for-finding-me/", image: "https://longreads.com/wp-content/uploads/2025/07/bubert_thankyou-7.jpg" },
95        { title: "Eight Limes, No More", author: "Mira Ptacin", excerpt: "A found list is a rare analog window into someone else\u2019s needs \u2014 an accidental autobiography.", url: "https://longreads.com/2025/07/15/eight-limes-no-more-found-lists-poetry/", image: "https://longreads.com/wp-content/uploads/2025/07/Eight-Limes-7.jpg" },
96        { title: "How to Observe", author: "Erika Howsare", excerpt: "Searching for ritual during a season of mystery.", url: "https://longreads.com/2025/07/10/attention-ritual-art-observation/", image: "https://longreads.com/wp-content/uploads/2025/06/HowToObserve_Jetty2.png" },
97        { title: "The Kitchen with Two Doors", author: "Kristina Kasparian", excerpt: "On the insatiable hunger for belonging.", url: "https://longreads.com/2024/11/12/hunger-belonging-pregnancy-surrogate-kristina-kasparian/", image: "https://longreads.com/wp-content/uploads/2024/11/KitchenAComplementary.png" },
98        { title: "Communion", author: "Raleigh McCool", excerpt: "How a lonely man in his 30s found community in an unlikely place: spin class.", url: "https://longreads.com/2024/09/05/spin-masculinity-loneliness-friendship/", image: "https://longreads.com/wp-content/uploads/2024/08/Communion-essay-image-FINAL.png" },
99        { title: "Finding Worth Among the Echoes", author: "Cameron Carr", excerpt: "Faded music dreams, a fledgling family farm, and a search for new definitions of work and success.", url: "https://longreads.com/2024/06/18/worth-work-success-music/", image: "https://longreads.com/wp-content/uploads/2024/06/Finding-Worth-Among-the-Echoes-guitar-music-barn-watercolor.jpg" },
100        { title: "My Name Is a Mountain", author: "Montserrat Andree Carty", excerpt: "On language, belonging, and embracing the different versions of ourselves.", url: "https://longreads.com/2024/04/23/mountain-montserrat-spain-identity-language-culture-name-belonging/", image: "https://longreads.com/wp-content/uploads/2024/04/Montserrat-Essay-B.png" },
101        { title: "Stumbling Can Be Lovely", author: "Devin Kelly", excerpt: "On the many ways we fall \u2014 and the beauty of getting back up.", url: "https://longreads.com/2024/03/07/stumbling-can-be-lovely-devin-kelly/", image: "https://longreads.com/wp-content/uploads/2024/02/StumblingCanBeLovely.jpg" },
102        { title: "Flying Solo", author: "Kristina Kasparian", excerpt: "On self-love and self-acceptance while aging in a disabled body.", url: "https://longreads.com/2024/02/06/travel-milan-disability-aging-ableism-self-acceptance/", image: "https://longreads.com/wp-content/uploads/2024/02/plane-heart-green.png" },
103        { title: "How to Survive a Car Crash in 10 Easy Steps", author: "Anne Lagamayo", excerpt: "A journalist navigates a world forever changed by her traumatic brain injury.", url: "https://longreads.com/2023/05/11/how-to-survive-a-car-crash-traumatic-brain-injury-10-easy-steps/", image: "https://longreads.com/wp-content/uploads/2023/05/puzzle-brain-gray-scratches.png" },
104        { title: "Love Song to Costco", author: "Yuxi Lin", excerpt: "In the great halls of Costco, two of our greatest fears are assuaged \u2014 that of not having enough, and that of not being enough.", url: "https://longreads.com/2022/06/16/love-song-to-costco/", image: "https://longreads.com/w
104p-content/uploads/2022/06/costco_amagasaki-2.png" },
105        { title: "I Miss It All", author: "Devin Kelly", excerpt: "Against the commodification of community.", url: "https://longreads.com/2021/07/22/i-miss-it-all-devin-kelly/", image: "https://longreads.com/wp-content/uploads/2021/07/gettyimages-1206237961-scaled.jpg" },
106        { title: "On Solitude (and Isolation and Loneliness [and Brackets])", author: "Sarah Fay", excerpt: "Four years spent in solitude, viewed through the lens of punctuation.", url: "https://longreads.com/2020/03/17/solitude-isolation-loneliness-brackets/", image: "https://longreads.com/wp-content/uploads/2020/01/onsolitude_v1.jpg" }
107      ]
108    },
109    flaneur: {
110      label: "The Fl\u00e2neur",
111      description: "From a Sade album to a British condiment to the secret history of ice cream trucks, you find meaning in unexpected corners. You don\u2019t sort culture into high and low; you just want a writer who cares enough to go deep\u2014and tells an irresistible story. Your reading list is unpredictable, and that\u2019s exactly how you like it.",
112      stories: [
113        { title: "An Internet of Checkpoints", author: "Bijan Stephen", excerpt: "A mysterious YouTube video gave thousands of people a place to breathe. Then it vanished.", url: "https://longreads.com/2026/02/26/internet-checkpoint-taia777-donkey-kong/", image: "https://longreads.com/wp-content/uploads/2026/02/Bijan_Checkpoint_5.png" },
114        { title: "David Lynch Was Here", author: "Katherine Cusumano", excerpt: "A dispatch from the real Twin Peaks, where fans of the director flocked after his death.", url: "https://longreads.com/2025/01/30/real-twin-peaks-david-lynch/", image: "https://longreads.com/wp-content/uploads/2025/01/RZY_20250117_171015_0176.jpg" },
115        { title: "40 Years Later: Sade, \u201cPromise\u201d", author: "Hanif Abdurraqib", excerpt: "\u201cPromise\u201d isn\u2019t about love so much as giving your heart over, and enduring the failures that come with the exchange.", url: "https://longreads.com/2025/11/20/sade-promise-40th-anniversary/", image: "https://longreads.com/wp-content/uploads/2025/11/sade-bg.jpg" },
116        { title: "30 Years Later: Groove Theory", author: "Hanif Abdurraqib", excerpt: "\u201cGroove Theory\u201d tries to make the work of staying in love feel as easy as possible, even when it isn\u2019t.", url: "https://longreads.com/2025/10/23/groove-theory-30th-anniversary/", image: "https://longreads.com/wp-content/uploads/2025/10/groovetheory.png" },
117        { title: "99 Problems: The Ice Cream Truck\u2019s Surprising History", author: "Olivia Potts", excerpt: "From crime panics to TikTok, summer\u2019s favorite vehicle has driven a bumpy road.", url: "https://longreads.com/2025/08/26/ice-cream-truck-history-hysteria/", image: "https://longreads.com/wp-content/uploads/2025/08/3.png" },
118        { title: "Fast Times on America\u2019s Slowest Train", author: "Harrison Scott Key", excerpt: "A surreal train ride between Chicago and New Orleans proves Amtrak still has a lot to offer. (Not including speed or the food.)", url: "https://longreads.com/2023/10/03/delights-of-train-travel-on-amtrak/", image: "https://longreads.com/wp-content/uploads/2023/09/Copy-of-GettyImages-652755218.pdf.png" },
119        { title: "The Strangely Beautiful Experience of Google Reviews", author: "Will McCarthy", excerpt: "Glimpses of humanity in an unlikely corner of the internet.", url: "https://longreads.com/2023/01/03/the-strangely-beautiful-experience-of-google-reviews/", image: "https://longreads.com/wp-content/uploads/2022/12/google-reviews-on-map.jpg" },
120        { title: "\u201cBRAAAAM!\u201d: The Sound that Invaded Hollywood", author: "Adrian Daub", excerpt: "How Inception changed the way we listen to movies.", url: "https://longreads.com/2016/12/08/braaam-inception-hollywood-soundtracks/", image: "https://longreads.com/wp-content/uploads/2016/12/20161205-braaam.jpg" },
121        { title: "But Who Tells Them What to Sing?", author: "Adrian Daub", excerpt: "How Hollywood film choruses came to bellow perfectly nonsensical prose with utter conviction.", url: "https://longreads.com/2021/09/02/but-who-tells-them-what-to-sing/", image: "https://longreads.com/w
121p-content/uploads/2021/09/gettyimages-183305123-scaled.jpg" },
122        { title: "The God Phone", author: "Leora Smith", excerpt: "What happens when ordinary people play God to strangers? The history of one of the oldest art installations at Burning Man.", url: "https://longreads.com/2020/01/14/the-god-phone/", image: "https://longreads.com/wp-content/uploads/2019/10/talk-to-god.jpg" },
123        { title: "Marmalade: A Very British Obsession", author: "Olivia Potts", excerpt: "Captain Scott took jars to the Antarctic. Edmund Hillary took one up Everest. Marmalade is part of the British national myth.", url: "https://longreads.com/2020/07/23/marmalade-a-very-british-obsession/", image: "https://longreads.com/wp-content/uploads/2020/07/gettyimages-502124497.jpg" },
124        { title: "How to Learn Everything: The MasterClass Diaries", author: "Irina Dumitrescu", excerpt: "A professor embarks on a six-month binge of celebrity-led online courses.", url: "https://longreads.com/2020/08/20/how-to-learn-everything-the-masterclass-diaries/", image: "https://longreads.com/wp-content/uploads/2020/08/gettyimages-540549530-1-scaled.jpg" },
125        { title: "Unleashed in Paris", author: "Kate Gavino", excerpt: "As a semi-professional dog walker in Paris, Kate Gavino has found a comfortable way to learn French.", url: "https://longreads.com/2019/04/03/unleashed-in-paris/", image: "https://longreads.com/wp-content/uploads/2019/03/cover-1.jpg" },
126        { title: "Home Is a Cup of Tea", author: "Candace Rose Rardon", excerpt: "A search for home through the different teas discovered while traveling.", url: "https://longreads.com/2017/07/03/home-is-a-cup-of-tea/", image: "https://longreads.com/wp-content/uploads/2017/06/home_header.jpg" }
127      ]
128    },
129    archivist: {
130      label: "The Archivist",
131      description: "You\u2019re drawn to the stories hiding inside official histories: a forgotten assassination of a congressman, a deportation erased from a town's memory, a queen who kicked her husband off the throne. You read to understand how power works, who got left out of the record, and what it costs when we stop paying attention.",
132      stories: [
133        { title: "Vigilantes at Dawn", author: "Masha Hamilton", excerpt: "A forgotten deportation, a family archive, and the cost of belonging.", url: "https://longreads.com/2026/02/19/bisbee-deportation-vigilantes-miners/", image: "https://longreads.com/wp-content/uploads/2026/02/Bisbee-09-scaled.jpg" },
134        { title: "The Eloquent Vindicator in the Electric Room", author: "Drew Johnson", excerpt: "No one remembers the assassination of Congressman James M. Hinds. What do we risk by forgetting?", url: "https://longreads.com/2025/09/09/congressman-james-hinds-assassination/", image: "https://longreads.com/wp-content/uploads/2025/09/Johnson_Hinds_2.png" },
135        { title: "Uncanny Testimony", author: "Benjamin Charles Germain Lee", excerpt: "As the last Holocaust survivors near the end of their lives, an AI scholar grapples with technology that promises to freeze them in time.", url: "https://longreads.com/2025/09/25/ai-holocaust-survivors-memory/", image: "https://longreads.com/wp-content/uploads/2025/09/Uncanny-Testimony-v2.png" },
136        { title: "Disneyland of the Dead", author: "Ralph Jones", excerpt: "London\u2019s Highgate Cemetery shows us just how hard it is to keep the dead buried.", url: "https://longreads.com/2025/07/22/problem-of-burying-dead-bodies/", image: "https://longreads.com/wp-content/uploads/2025/07/Highgate-5.png" },
137        { title: "Queens of Infamy: Isabella of France", author: "Anne Theriault", excerpt: "Married off at age 12, Isabella put up with her husband\u2019s shenanigans over decades. Eventually, the She-Wolf of France had had enough.", url: "https://longreads.com/2022/06/21/queens-of-infamy-isabella-of-france/", image: "https://longreads.com/wp-content/uploads/2022/06/isabella-of-france-queens-of-infamy-final-2-blue-scaled.jpg" },
138        { title: "Shades of Grey", author: "Ashley Stimpson", excerpt: "In 2018, Floridians voted overwhelmingly to end greyhound racing, a sport they were told was archaic and inhumane. What if they were wrong?", url: "https://longreads.com/2020/10/29/sha
138des-of-grey/", image: "https://longreads.com/wp-content/uploads/2020/10/gettyimages-174622197-scaled.jpg" },
139        { title: "The Strange and Dangerous World of America\u2019s Big Cat People", author: "Rachel Nuwer", excerpt: "A murder-for-hire plot helped expose the dark side of exotic animal ownership in the U.S.", url: "https://longreads.com/2020/03/16/tiger-trafficking-in-america/", image: "https://longreads.com/wp-content/uploads/2020/03/cat-people.png" },
140        { title: "Debt Demands a Body", author: "Kristin Collier", excerpt: "The future that debt chose for me \u2014 and for many people \u2014 included a lot of shame, confusion, and pain.", url: "https://longreads.com/2021/12/01/debt-demands-a-body/", image: "https://longreads.com/wp-content/uploads/2021/11/3-1.png" }
141      ]
142    },
143    naturalist: {
144      label: "The Naturalist",
145      description: "You read with the same attention you\u2019d bring to a long walk somewhere wild. You\u2019re drawn to the nonhuman world\u2014its beauty, its scale, its urgency\u2014and to writers who can translate it into language that makes you care. You know there\u2019s no better use of 5,000 words than a whale.",
146      stories: [
147        { title: "By All Measures", author: "B. R. Cohen", excerpt: "Our problems are too vast, our distance from them too great. How do we navigate our derangement of scale?", url: "https://longreads.com/2026/01/13/scale-climate-doomsday-clock/", image: "https://longreads.com/wp-content/uploads/2026/01/Clocks_2.png" },
148        { title: "Swamp People", author: "Ashley Stimpson", excerpt: "Finding refuge and resilience in America\u2019s most reviled landscapes.", url: "https://longreads.com/2025/10/02/to-love-a-swamp/", image: "https://longreads.com/wp-content/uploads/2025/09/Swamp_F.jpg" },
149        { title: "The Rip in the World", author: "Jonah Walters", excerpt: "On volcanoes, earthquakes, and our attraction to disaster.", url: "https://longreads.com/2024/10/24/iceland-volcano-disaster-jonah-walters/", image: "https://longreads.com/wp-content/uploads/2024/10/RipC.png" },
150        { title: "Danger on the Divide", author: "Maggie Slepian", excerpt: "Just because you don\u2019t recognize trouble doesn\u2019t mean it\u2019s not there.", url: "https://longreads.com/2024/08/15/danger-mountain-biking-maggie-slepian/", image: "https://longreads.com/wp-content/uploads/2024/08/DangerOnTheDivideB.jpg" },
151        { title: "Nathan", author: "Dan Musgrave", excerpt: "Language lessons with an extraordinary ape.", url: "https://longreads.com/2023/05/09/nathan/", image: "https://longreads.com/wp-content/uploads/2023/05/Untitled-2400-×-1400-px.png" },
152        { title: "\u2018That Girl Is Going to Get Herself Killed\u2019", author: "Krista Diamond", excerpt: "There is risk in the wilderness \u2014 even in mild adventures \u2014 and yet we still seek to reason with it, to control it, and to tempt it.", url: "https://longreads.com/2022/11/15/death-in-national-parks/", image: "https://longreads.com/wp-content/uploads/2022/11/GettyImages-120881217-scaled.jpg" },
153        { title: "Dreaming of Water with Tiger Salamanders", author: "Sam Keck Scott", excerpt: "There is no more urgent form of communication than going extinct.", url: "https://longreads.com/2022/03/22/dreaming-of-water-with-tiger-salamanders/", image: "https://longreads.com/wp-content/uploads/2022/03/untitled-design-17.png" },
154        { title: "Bones, Bones: How to Articulate a Whale", author: "Peter Wayne Moe", excerpt: "I have sat inside her rib cage. And yet I know nothing about her.", url: "https://longreads.com/2022/02/22/bones-bones-how-to-articulate-a-whale/", image: "https://longreads.com/wp-content/uploads/2022/02/l1060599-scaled.jpeg" },
155        { title: "The Hunt for Planet Nine", author: "Shannon Stirone", excerpt: "What will it take to find the biggest missing object in our solar system?", url: "https://longreads.com/2019/01/22/the-hunt-for-planet-nine/", image: "https://longreads.com/wp-content/uploads/2019/01/final.png" },
156        { title: "An Atlas of the Cosmos", author: "Shannon Stirone", excerpt: "We\u2019ve mapped Mars, the Moon, the solar system, even our galaxy. Which means there is only one thing left to understand.", url: "https://longreads.com/2020/10/27/an-atlas-of-the-cosmos/", image: "https://longreads.com/w
156p-content/uploads/2020/10/glennharvey_2020_11_01_longreads_final-2.jpg" }
157      ]
158    }
159  };
160
161  // === CONFIGURATION ===
162
163  // Number of story recommendations shown per result
164  var STORIES_TO_SHOW = 3;
165  var TOTAL_QUESTIONS = questions.length;
166  // Question 4 (index 3) breaks ties — it asks about documentaries,
167  // which tends to reveal core interests most reliably.
168  var TIEBREAKER_INDEX = 3;
169
170  // === STATE ===
171
172  var currentQuestion = 0;
173  var scores = { humanist: 0, flaneur: 0, archivist: 0, naturalist: 0 };
174  var tiebreakerAnswer = null;
175
176  // === DOM REFERENCES ===
177
178  var quizScreen = document.getElementById( "lr-quiz-screen" );
179  var resultsScreen = document.getElementById( "lr-results-screen" );
180  var qContainer = document.getElementById( "lr-question-container" );
181  var pLabel = document.getElementById( "lr-progress-label" );
182  var pFill = document.getElementById( "lr-progress-fill" );
183  var pBar = pFill.parentElement;
184
185  // === RENDERING ===
186
187  /** Renders question i: updates progress bar, builds answer buttons via DOM. */
188  function renderQ( i ) {
189    var q = questions[ i ];
190    var pct = Math.max( Math.round( ( i / TOTAL_QUESTIONS ) * 100 ), 8 );
191    pLabel.textContent = "Question " + ( i + 1 ) + " of " + TOTAL_QUESTIONS;
192    pFill.style.width = pct + "%";
193    pBar.setAttribute( "aria-valuenow", pct );
194
195    qContainer.innerHTML = "";
196
197    var h2 = document.createElement( "h2" );
198    h2.textContent = q.question;
199
200    var ul = document.createElement( "ul" );
201    ul.className = "quiz-answers";
202    ul.setAttribute( "role", "list" );
203
204    for ( var j = 0; j < q.answers.length; j++ ) {
205      var li = document.createElement( "li" );
206      var btn = document.createElement( "button" );
207      btn.textContent = q.answers[ j ].text;
208      btn.setAttribute( "data-index", j );
209      btn.addEventListener( "click", function () {
210        onAnswer( parseInt( this.getAttribute( "data-index" ) ) );
211      } );
212      li.appendChild( btn );
213      ul.appendChild( li );
214    }
215
216    qContainer.appendChild( h2 );
217    qContainer.appendChild( ul );
218
219    // Focus the first answer so keyboard users land in the right place
220    var firstBtn = qContainer.querySelector( "button" );
221    if ( firstBtn ) { setTimeout( function () { firstBtn.focus(); }, 100 ); }
222  }
223
224  /** Handles answer selection: increments score, advances or shows results. */
225  function onAnswer( idx ) {
226    var cat = questions[ currentQuestion ].answers[ idx ].category;
227    scores[ cat ]++;
228    if ( currentQuestion === TIEBREAKER_INDEX ) { tiebreakerAnswer = cat; }
229    currentQuestion++;
230    if ( currentQuestion < TOTAL_QUESTIONS ) { renderQ( currentQuestion ); } else { showResults(); }
231  }
232
233  // === SCORING ===
234
235  /** Returns the winning category. Uses tiebreaker answer if scores are tied. */
236  function getWinner() {
237    var cats = [ "humanist", "flaneur", "archivist", "naturalist" ];
238    var max = 0;
239    for ( var i = 0; i < cats.length; i++ ) {
240      if ( scores[ cats[ i ] ] > max ) { max = scores[ cats[ i ] ]; }
241    }
242    var tied = [];
243    for ( var j = 0; j < cats.length; j++ ) {
244      if ( scores[ cats[ j ] ] === max ) { tied.push( cats[ j ] ); }
245    }
246    if ( tied.length === 1 ) { return tied[ 0 ]; }
247    if ( tiebreakerAnswer && tied.indexOf( tiebreakerAnswer ) > -1 ) { return tiebreakerAnswer; }
248    // Random pick among tied categories as a fair fallback
249    return tied[ Math.floor( Math.random() * tied.length ) ];
250  }
251
252  /** Fisher-Yates shuffle to pick n random items without modifying the original. */
253  function pickRandom( arr, n ) {
254    var copy = arr.slice();
255    for ( var i = copy.length - 1; i > 0; i-- ) {
256      var j = Math.floor( Math.random() * ( i + 1 ) );
257      var tmp = copy[ i ]; copy[ i ] = copy[ j ]; copy[ j ] = tmp;
258    }
259    return copy.slice( 0, n );
260  }
261
262  // === ACTIONS ===
263
264  /** Copies the current URL (with ?result= param) to the clipboard. */
265  function handleShare() {
266    var conf = document.getElementById( "lr-share-confirm" );
267    if ( navigator.clipboard ) {
268      navigator.clipboard.writeText( window.location.href ).then( function () {
269        conf.style.display = "inline";
270        setTimeout( function () { conf.style.display = "none"; }, 3000 );
271      } ).catch( function () {
272        prompt( "Copy this link to share your result:", window.location.href );
273      } );
274    } else {
275      prompt( "Copy this link to share your result:", window.location.href );
276    }
277  }
278
279  /** Resets all state and returns to question 1. */
280  function handleRestart() {
281    currentQuestion = 0;
282    scores = { humanist: 0, flaneur: 0, archivist: 0, naturalist: 0 };
283    tiebreakerAnswer = null;
284    if ( history.replaceState ) {
285      var url = new URL( window.location.href );
286      url.searchParams.delete( "result" );
287      history.replaceState( null, "", url.toString() );
288    }
289    resultsScreen.style.display = "none";
290    quizScreen.style.display = "block";
291    renderQ( 0 );
292    window.scrollTo( { top: 0, behavior: "smooth" } );
293  }
294
295  // Attach share and restart handlers once
296  document.getElementById( "lr-btn-share" ).addEventListener( "click", handleShare );
297  document.getElementById( "lr-btn-restart" ).addEventListener( "click", handleRestart );
298
299  // === RESULTS ===
300
301  /**
302   * Displays the results screen: winner label, description, and 3 random
303   * story cards. Updates the URL with ?result=category for sharing.
304   */
305  function showResults() {
306    pFill.style.width = "100%";
307    pBar.setAttribute( "aria-valuenow", 100 );
308    pLabel.textContent = "Your result";
309    var cat = getWinner();
310    var r = results[ cat ];
311    document.getElementById( "lr-result-label" ).textContent = r.label;
312    document.getElementById( "lr-result-description" ).textContent = r.description;
313
314    var cardsContainer = document.getElementById( "lr-story-cards" );
315    cardsContainer.innerHTML = "";
316
317    if ( !r.stories || r.stories.length === 0 ) {
318      var emptyMsg = document.createElement( "p" );
319      emptyMsg.style.cssText = "text-align:center;color:#666;font-style:italic;";
320      emptyMsg.textContent = "No stories available right now. Check back soon!";
321      cardsContainer.appendChild( emptyMsg );
322    }
323
324    var stories = pickRandom( r.stories || [], STORIES_TO_SHOW );
325
326    for ( var i = 0; i < stories.length; i++ ) {
327      var s = stories[ i ];
328
329      var card = document.createElement( "a" );
330      card.className = "story-card";
331      card.href = s.url;
332      card.target = "_blank";
333      card.rel = "noopener";
334      card.setAttribute( "role", "listitem" );
335
336      var img = document.createElement( "img" );
337      img.src = s.image;
338      img.alt = "Illustration for " + s.title;
339      img.loading = "lazy";
340      img.onerror = function () {
341        this.onerror = null;
342        this.alt = "";
343        this.style.background = "#eeeeee";
344        this.removeAttribute( "src" );
345      };
346
347      var body = document.createElement( "div" );
348      body.className = "story-card-body";
349
350      var title = document.createElement( "p" );
351      title.className = "story-card-title";
352      title.textContent = s.title;
353
354      var author = document.createElement( "p" );
355      author.className = "story-card-author";
356      author.textContent = s.author;
357
358      var excerpt = document.createElement( "p" );
359      excerpt.className = "story-card-excerpt";
360      excerpt.textContent = s.excerpt;
361
362      var cta = document.createElement( "span" );
363      cta.className = "story-card-cta";
364      cta.textContent = "Read this story \u2192";
365
366      body.appendChild( title );
367      body.appendChild( author );
368      body.appendChild( excerpt );
369      body.appendChild( cta );
370      card.appendChild( img );
371      card.appendChild( body );
372      cardsContainer.appendChild( card );
373    }
374
375    if ( history.replaceState ) {
376      var url = new URL( window.location.href );
377      url.searchParams.set( "result", cat );
378      history.replaceState( null, "", url.toString() );
379    }
380    quizScreen.style.display = "none";
381    resultsScreen.style.display = "block";
382    window.scrollTo( { top: 0, behavior: "smooth" } );
383
384    // Focus the result heading so screen readers announce it
385    var resultLabel = document.getElementById( "lr-result-label" );
386    setTimeout( function () { resultLabel.focus(); }, 100 );
387  }
388
389  // === INITIALIZATION ===
390
391  /**
392   * Checks for a ?result=category URL param (from shared links).
393   * If valid, skips the quiz and jumps straight to that result.
394   */
395  function checkUrl() {
396    var p = new URLSearchParams( window.location.search );
397    var r = p.get( "result" );
398    if ( r && results[ r ] ) {
399      scores[ r ] = 7;
400      tiebreakerAnswer = r;
401      showResults();
402      return true;
403    }
404    return false;
405  }
406
407  if ( !checkUrl() ) { renderQ( 0 ); }
408
409}());

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.