Skip to main content
edited body
Source Link

"Is there a way I can "extract" a value of a variable from another method?"

Is there a way I can "extract" a value of a variable from another method?

A method can return a value, so you can assign the variable you need the value of to the call of this method. You just need to think about what j actually represents and what the action that is iterating j meaningfully is. In this case it's pretty clear; you are having player A draw a set of cards from the deck and then player B draw a set of cards from the deck. So you could have a method like PlayHand() where you have a player A play their hand according to the logic you have articulated while returning the value you need for player B. Think about what "PlayHand" says in actual language and then what of your code accomplishes that task.

There is more to say but I will have to get to it later. Hope this helps!

"Is there a way I can "extract" a value of a variable from another method?"

A method can return a value, so you can assign the variable you need the value of to the call of this method. You just need to think about what j actually represents and what the action that is iterating j meaningfully is. In this case it's pretty clear; you are having player A draw a set of cards from the deck and then player B draw a set of cards from the deck. So you could have a method like PlayHand() where you have a player A play their hand according to the logic you have articulated while returning the value you need for player B. Think about what "PlayHand" says in actual language and then what of your code accomplishes that task.

There is more to say but I will have to get to it later. Hope this helps!

Is there a way I can "extract" a value of a variable from another method?

A method can return a value, so you can assign the variable you need the value of to the call of this method. You just need to think about what j actually represents and what the action that is iterating j meaningfully is. In this case it's pretty clear; you are having player A draw a set of cards from the deck and then player B draw a set of cards from the deck. So you could have a method like PlayHand() where you have a player A play their hand according to the logic you have articulated while returning the value you need for player B. Think about what "PlayHand" says in actual language and then what of your code accomplishes that task.

There is more to say but I will have to get to it later. Hope this helps!

Source Link

"Is there a way I can "extract" a value of a variable from another method?"

A method can return a value, so you can assign the variable you need the value of to the call of this method. You just need to think about what j actually represents and what the action that is iterating j meaningfully is. In this case it's pretty clear; you are having player A draw a set of cards from the deck and then player B draw a set of cards from the deck. So you could have a method like PlayHand() where you have a player A play their hand according to the logic you have articulated while returning the value you need for player B. Think about what "PlayHand" says in actual language and then what of your code accomplishes that task.

There is more to say but I will have to get to it later. Hope this helps!