Inline quizzes

Stop and think of the last article you read and recite three facts from it. No? That article poured pearls of wisdom onto you, but they all rolled away. The article gave, but you could not even summon the effort to take.

Most of what I have learned has been through activity: exercises at school and university, problem-solving at work, writing blog posts at home. Effective writing encourages “active reading”. Our school textbooks knew how: every page is a mixture of description and exercises. The textbook gives a little, and asks a little in return. It’s a reciprocal, healthy relationship. In contrast, articles are pornography: attractive, short-term entertainment, asking for nothing, after which you feel empty.

The textbook’s paper is passive, unable to hide its secrets. But our webpages are active, and we can demand a little from our readers. At the start of this post, I asked you to recall the last article you read. Did you actually do it? No, I don’t believe you did! But I don’t blame you. Nothing stopped you skipping over the question to my conclusion!

That above redacted text is an example of an inline quiz. You’ll need to click it to see the answer. You can drop an inline quiz into most explanatory text. The following is an example of use, beginning an explanation of RSA.

An RSA private key consists of two primes, p and q. Its corresponding public key, n, is p × q. For example, if p=5 and q=7, then the public key is 5×7=35. Given the public key n, it’s hard to compute p and q. For example, if Alice’s public key n=143, what are p and q? 11 and 13, because 11×13=143. Even with these tiny numbers, this should have taken some thought! Alice also chooses a public exponent e, e.g. 7, then sends (n, e) to Bob, so her full public key is (n=143, e=7). Now Bob wants to send Alice the secret number m=42. To do so, Bob calculates ciphertext c=pow(m,e), modulo n. What ciphertext c should Bob send to Alice? 81. pow(42,7) = 230539333248, but modulo 143, c=81. ...

I believe the inline questions make the explanation more immersive. Even you didn’t answer all the questions yourself, you still had to participate to reveal the text. I’m going to try including these inline quizzes in most explanatory text I write on this blog.

These inline quizzes are implemented with:

What are <i>p</i> and <i>q</i>? <span class="answer">11 and 13.</span>
document.addEventListener("DOMContentLoaded", () =>
  Array.prototype.forEach.call(
    document.getElementsByClassName("answer"),
    el => el.addEventListener("click", () => el.classList.add("revealed"))));
.answer {
  border-color: #8ec58e;
  padding: 0 0.3rem;
  border-radius: 3px; border: 2px solid #8585d0;
}
.answer:not(.revealed) {
  color: rgba(0,0,0,0);
  background-image: url(/assets/question-mark.svg);
  cursor: pointer;
}
Tagged #blog.

Similar posts

More by Jim

👋 I'm Jim, a full-stack product engineer. Want to build an amazing product and a profitable business? Read more about me or Get in touch!

This page copyright James Fisher 2017. Content is not associated with my employer. Found an error? Edit this page.