I am a balding man. The son of a balding man. Grandson of a bald man. It’s a curse handed down through generations, something I’ve been battling for more than a decade with mild success and very little grace. According to the Canadian Dermatology Association, 80 per cent of men “will have some degree of baldness by age 70.”

If you – like me – are thinning up top, dealing with hair loss can feel like a choose your own adventure game. There are many different pathways to take. One decision may help regrow your luscious locks. Another wastes thousands of dollars on magic beans as smooth as your crowning head. For the past three months I’ve spent hours chatting with experts about a number of different options for hair loss, compiling a list of treatments and best practices to share with our readers. But to start off the journey, the first question is simple.

“;
} else {
optionsHtml = scene.options.map((opt, idx) => {
return `

${opt.text}

`;
}).join(“”);
optionsHtml = `

${optionsHtml}

`;
}

const sceneTypeClass = scene.isEnding ? ‘ending-scene’ : ‘choice-scene’;
const firstQuestionClass = currentScene === ‘start’ ? ‘ first-question’ : ”;

quizBox.innerHTML = `

${imgHtml}

${scene.question}

${optionsHtml}

`;

if (scene.isEnding) {
const restartBtn = document.getElementById(‘restartBtn’);
if (restartBtn) {
restartBtn.addEventListener(‘click’, restartAdventure);
}
} else {
document.querySelectorAll(‘.quiz-option’).forEach(opt => {
opt.addEventListener(‘click’, function () {
const nextScene = this.dataset.next;
const choiceText = this.dataset.text;
const explanation = this.dataset.explanation;
if (nextScene) {
this.classList.add(‘selected’);
const labelSpan = this.querySelector(‘.quiz-option-label’);
if (labelSpan) {
labelSpan.style.textDecoration = ‘underline’;
labelSpan.style.textDecorationThickness=”2.5px”;
labelSpan.style.textUnderlineOffset=”4px”;
labelSpan.style.textDecorationColor=”#4D98D2″;
}

document.querySelectorAll(‘.quiz-option’).forEach(o => {
o.style.pointerEvents=”none”;
});

showResult(explanation, nextScene);

setTimeout(() => {
const allAnswerSections = document.querySelectorAll(‘.answer-section-item’);
const lastAnswerSection = allAnswerSections[allAnswerSections.length – 1];
if (lastAnswerSection && lastAnswerSection.style.display !== ‘none’) {
const elementPosition = lastAnswerSection.getBoundingClientRect().top + window.pageYOffset;
const offsetPosition = elementPosition – 62; // 52px header + 10px spacing

// Adjust duration in milliseconds
smoothScrollTo(offsetPosition, 650);
}
}, 650);

currentScene = nextScene;
storyPath.push(nextScene);
saveState();
submitChoice(storyPath);
}
});
});
}

updateStartOverButton();
}

function updateStartOverButton() {
const clearBtn = document.getElementById(‘clearQuizBtn’);
if (!clearBtn) return;

const dynamicAnswers = document.querySelectorAll(‘.answer-section-item’);
const dynamicResults = document.querySelectorAll(‘.result-box-item’);
const isAtStart = currentScene === ‘start’ && dynamicAnswers.length === 0 && dynamicResults.length === 0;

if (isAtStart) {
clearBtn.classList.add(‘disabled’);
clearBtn.disabled = true;
clearBtn.setAttribute(‘data-tooltip’, ‘Already at the start’);
} else {
clearBtn.classList.remove(‘disabled’);
clearBtn.disabled = false;
clearBtn.removeAttribute(‘data-tooltip’);
}
}

function showResult(explanation, nextSceneId) {
const pageContainer = document.querySelector(‘.page-container’);
const buttonRow = document.querySelector(‘.button-row’);
if (!pageContainer || !buttonRow) return;

const nextScene = storyData[nextSceneId];
if (!nextScene) return;

const currentScrollY = window.pageYOffset;

const newAnswerSection = document.createElement(‘div’);
newAnswerSection.className=”answer-section-item”;
const explanationHtml = explanation ? `

${explanation}

` : ”;
newAnswerSection.innerHTML = explanationHtml;
newAnswerSection.style.display = explanation ? ‘block’ : ‘none’;
pageContainer.insertBefore(newAnswerSection, buttonRow);

window.scrollTo(0, currentScrollY);

if (nextScene.isEnding) {
updateStartOverButton();
return;
}

const newResultBox = document.createElement(‘div’);
newResultBox.className=”result-box-item”;

const imgHtml = nextScene.image ? “ : “”;

const nextOptionsHtml = nextScene.options.map((opt, idx) => {
return `

${opt.text}

`;
}).join(“”);

newResultBox.innerHTML = `

${imgHtml}

${nextScene.question}

${nextOptionsHtml}

`;

const scrollBeforeInsert = window.pageYOffset;
pageContainer.insertBefore(newResultBox, buttonRow);
window.scrollTo(0, scrollBeforeInsert);

updateStartOverButton();

newResultBox.querySelectorAll(‘.quiz-option’).forEach(opt => {
opt.addEventListener(‘click’, function () {
const nextScene = this.dataset.next;
const choiceText = this.dataset.text;
const explanation = this.dataset.explanation;
if (nextScene) {
this.classList.add(‘selected’);
const labelSpan = this.querySelector(‘.quiz-option-label’);
if (labelSpan) {
labelSpan.style.textDecoration = ‘underline’;
labelSpan.style.textDecorationThickness=”2.5px”;
labelSpan.style.textUnderlineOffset=”4px”;
labelSpan.style.textDecorationColor=”#4D98D2″;
}

newResultBox.querySelectorAll(‘.quiz-option’).forEach(o => {
o.style.pointerEvents=”none”;
});

showResult(explanation, nextScene);

setTimeout(() => {
const allAnswerSections = document.querySelectorAll(‘.answer-section-item’);
const lastAnswerSection = allAnswerSections[allAnswerSections.length – 1];
if (lastAnswerSection && lastAnswerSection.style.display !== ‘none’) {
const elementPosition = lastAnswerSection.getBoundingClientRect().top + window.pageYOffset;
const offsetPosition = elementPosition – 62; // 52px header + 10px spacing

// Adjust duration here (in milliseconds) – default is 600ms
smoothScrollTo(offsetPosition, 650);
}
}, 300);

currentScene = nextScene;
storyPath.push(nextScene);
saveState();
submitChoice(storyPath);
updateStartOverButton();
}
});
});
}

function restartAdventure() {
currentScene=”start”;
storyPath = [‘start’];
saveState();

const dynamicAnswers = document.querySelectorAll(‘.answer-section-item’);
const dynamicResults = document.querySelectorAll(‘.result-box-item’);

dynamicAnswers.forEach(el => el.remove());
dynamicResults.forEach(el => el.remove());

renderAdventure();
updateStartOverButton();

const quizBox = document.getElementById(‘quizBox’);
if (quizBox) {
const elementPosition = quizBox.getBoundingClientRect().top + window.pageYOffset;
const offsetPosition = elementPosition – 62; // 52px header + 10px spacing
smoothScrollTo(offsetPosition, 650);
}
}

function saveState() {
localStorage.setItem(STORAGE_KEY, JSON.stringify({
currentScene,
storyPath
}));
}

function loadState() {
const raw = localStorage.getItem(STORAGE_KEY);
if (!raw) return;
try {
const state = JSON.parse(raw);
if (state.currentScene && state.storyPath) {
const scene = storyData[state.currentScene];
if (!scene || scene.isEnding) {
localStorage.removeItem(STORAGE_KEY);
currentScene=”start”;
storyPath = [‘start’];
return;
}
currentScene = state.currentScene;
storyPath = state.storyPath;
}
} catch {
localStorage.removeItem(STORAGE_KEY);
currentScene=”start”;
storyPath = [‘start’];
}
}

function smoothScrollTo(targetPosition, duration = 600) {
const startPosition = window.pageYOffset;
const distance = targetPosition – startPosition;
let startTime = null;

function animation(currentTime) {
if (startTime === null) startTime = currentTime;
const timeElapsed = currentTime – startTime;
const progress = Math.min(timeElapsed / duration, 1);

const ease = progress < 0.5
? 2 * progress * progress
: 1 – Math.pow(-2 * progress + 2, 2) / 2;

window.scrollTo(0, startPosition + distance * ease);

if (timeElapsed < duration) {
requestAnimationFrame(animation);
}
}

requestAnimationFrame(animation);
}

loadState();
renderAdventure();
updateStartOverButton();

window.addEventListener(‘beforeunload’, () => {
localStorage.removeItem(STORAGE_KEY);
});

function submitChoice(path) {
const endpoint=”https://script.google.com/macros/s/AKfycbz6_5ByuzfNp25NRzYC9DzDbNyCN4Ma195Etl-PXb39GJUAqOmZ8IttJdlRB0vqRcs7/exec”;

fetch(endpoint, {
method: ‘POST’,
body: JSON.stringify({
storyPath: path.join(‘ -> ‘),
timestamp: new Date().toISOString()
}),
headers: { ‘Content-Type’: ‘application/json’ }
}).catch(err => {
console.log(‘Submission error:’, err);
});
}

Share.
Exit mobile version