The middle school students had spent 10 weeks learning computer programming code and gathered Thursday for a Jeopardy!-style competition to test their knowledge. The topics ranged from basic coding concepts (“What are variables?”) to questions on pop culture (“Who is the small screen science guy who is a dapper dresser?”) and also about the educational program’s sponsor, Capital One. (The category: “What’s in your wallet?”)

Then came the final round. The clue? “This show opens with: ‘Math, science, history, unraveling the mystery that all started with the . . . ‘”

Actress Mayim Bialik appeared on stage to read the answer: The Big Bang Theory, a sitcom about a gang of geeky and nerdy friends that, in its 10th season, remains one of the highest-rated sitcoms on television. One of the stars on the show, Bialik plays Amy Farrah Fowler, a neurobiologist in love with Sheldon Cooper, an idiosyncratic theoretical physicist, portrayed by Jim Parsons.

Bialik told the students another bit of trivia: like her TV character, she also has a PhD., earning a doctorate from UCLA in 2007.

“I don’t only play a scientist on TV, I am one in real life,” Bialik said.

In an interview with The Washington Post, Bialik said that she chose to speak at the event in McLean, Va. to promote subjects involving science, technology, engineering and math, known as STEM. Her surprise entrance during the contest for the Fairfax County students from Cooper, Glasgow, Kilmer and Poe middle schools was driven in part by her own foray into computer programming as a college student. At the time, she had to write code to better analyze data from MRI brain scans.

“Coding is complicated, but the best time to learn it is when you’re younger than I was,” Bialik said.

Bialik began her acting career as a child on the popular 1990s show “Blossom.” She later received a bachelor’s degree in neuroscience and Hebrew and Jewish studies at UCLA before beginning her doctoral research in “psychoneuroendocrinology.”

And to really understand what that is, you might need a PhD., as Bialik explained. She said it is the study of how hormonal secretions from the hypothalamus can affect relatively common mental health issues, such as Obsessive Compulsive Disorder, to rare genetic disorders, such as Prader-Willi syndrome, which can lead to physical abnormalities and alter brain development.

Bialik’s abiding interest in science led her to take part in the Capital One initiative, which involved 1,000 students in 20 schools throughout the country enrolled in a 10-week course in coding.

The program “is one right in my wheelhouse in terms of inspiring young people in learning aspects of STEM they may not have known about before,” Bialik said.

In her television role, Bialik’s character is a bespectacled intellect who embraces her own quirks. The show is as much about “poking fun of nerds and geek culture, but in another way we are celebrating it,” she said. “Part of why I do these things is to celebrate that there’s something beautiful and creative and interesting in a life that has a knowledge of STEM fields.”

Before gaining a recurring role on the show, Bialik taught neuroscience for five years to children who were being home-schooled. When she takes the set in character as a neurobiologist, there are still aspects of her former life teaching science that she wishes she hadn’t have to leave behind.

“I miss not having to wear makeup or not having to care what I look like,” Bialik said, noting that she used to teach her classes in pajamas.

In her current line of work, Bialik said, she can use her visibility as a high-profile actress on a comedy where being dorky is both empowering and part of the punchline to “encourage others to pursue a life in STEM.” She can also rely on her deep credentials as a published scientist in her current mission to ensure that students learn “that coding ultimately can be cool.”