Switch Players
Learn how can we switch between players.
We'll cover the following
What we have
If the game does not end, then we should prepare for the next round. In Tic-Tac-Toe, we need to switch the players before starting the next round.
Requirements of this module
In this task, we want to change the value of currentPlayer
variable. We first check its current value then modify it accordingly. We can return the new value on the basis of the current value of this variable. However, we have received the parameter as reference so that the changed value can be made visible in the caller function (play()
) without returning through explicit use of the return statement. The function switchPlayer()
should perform the following tasks:
- Receive
currentPlayer
as a reference parameter. - Check the current value of the parameter.
- Change the value of the parameter.
Try it yourself
All the functions are already defined. You just have to implement the given function and execute the code.
Get hands-on with 1400+ tech skills courses.