Thank you for the constructive feedback Jordan Huizenga.
Please refer to the fourth paragraph which I hope helps answer some of your questions. The purpose of the .map() function is to transform an object which is exactly what is happening here when the val attribute of the Object is inspected and changed depending on the current state. Even though in this case we are only looking at one attribute of the Object, there is an Object Class to represent a more complex use case one may build which contains many attributes that need to be inspected. In a production app there would not be any log statements so this is not a real concern for me.
I’ve linked to some more advanced examples in the resource section you can explore. If you create your own example please share in the comments below.