A plain JS demo of the Monty Hall problem
I haven’t used Javascript/ECMAscript much before - did learn the basics in my CompSci undergrad, and used a little JSX when at Kogan, but I was never that into frontend dev stuff. Trying to revise it today, I wrote this JS implementation of the “Let’s Make a Deal” game at the center of the “Monty Hall problem“.
How to Play
You’re on a TV game show, and have the choice of three doors. Behind one door is a car; behind the others, goats. You win the car if you choose the door with the car.
However. once you select a door, the host of the show will first open a different door, and show you a goat. They then ask you if you are sure you want to stick with the unopened door you’ve chosen, or switch to the other unopened door.
You must then make your final choice of which door to open.
The Monty Hall Problem
Is it to your advantage to switch doors when offered, or stick with the door you first picked?
One or the other is correct, and applying Bayes’ Theorem shows why. It’s not a 50/50 chance, which is widely considered the intuitive (but provably incorrect) response. A win rate tending towards two thirds (~66% below) should be achievable with optimal play over many games.
The Game
Choose a door to open:
Won 0 out of 0 games.