In terms of teaching your kids, that last change could be useful. We talk about abstraction a lot, but we don’t really show them examples. My current understanding is that abstraction at this level is all about creating domain specific functions and hiding implementation details. Here is an example of abstraction:
function playerTakesTurn (guess) {
checkCorrect(guess);
checkGameOver();
setBoard();
switchPlayer();
}
What we are doing is creating a description of what it means for a player to take a turn. We use function calls to create a language in the domain vocabulary. We also hide all implementation details completely.
We don’t get to objects until after the exam, but I intend to introduce my kids to the event object. The details are hidden in checkCorrect():
function checkCorrect (event) {
if (event.currentTargetId == randomButtonId) {
updateScoreBy(1);
} else {
updateScoreBy(-3);
}
}
More abstraction. This also allows me to show them how to use named functions in the onEvent call like this onEvent("button1","click",playerTakesTurn);
. More abstraction. I have been showing them how to do that for a while because I think it reinforces the idea of abstraction. I did this with Unit 5 lesson 5 puzzle 12 in a previous post Abstraction Demo