I recently made my very own version of the popular game “Simon” in JavaScript. It was the final project of freeCodeCamp’s front-end development certification and it taught me a lot about object-oriented programming.
I started by defining the constants LIGHT_DELAY, LIGHT_GAP, and MAX_ROUNDS, which set characteristics of the UI and the game itself, respectively.
Then the class “Round” was defined, along with methods to: keep track of which button was clicked, starting the game, generating random moves, cleaning moves, showing the generated pattern, changing the color intensity of the buttons, playing sounds, and finally checking if the moves generated and played are the same: