This is just a logic example for a student trying to do the same thing in JavaScript. You're welcome to use this for anything.