-
{status}
-
{moves}
+
);
}
-}
-// ========================================
+ renderButton() {
+ let choices = this.state.choices;
+ let button = null;
+ if (choices.length > 1 && choices[1]) {
+ button = (
+
+ );
+ } else {
+ button = (
+
+ );
+ }
+ return button;
+ }
-ReactDOM.render(
, document.getElementById("root"));
+ renderChoiceInputField() {
+ return (
+
+
Type or paste your choices
+
+
+ );
+ }
-function calculateWinner(squares) {
- const lines = [
- [0, 1, 2],
- [3, 4, 5],
- [6, 7, 8],
- [0, 3, 6],
- [1, 4, 7],
- [2, 5, 8],
- [0, 4, 8],
- [2, 4, 6],
- ];
- for (let i = 0; i < lines.length; i++) {
- const [a, b, c] = lines[i];
- if (squares[a] && squares[a] === squares[b] && squares[a] === squares[c]) {
- return squares[a];
+ renderCurrentChoices() {
+ let choices = this.state.choices;
+ let choicesToRender = choices.map((choice, index) => {
+ return
{choice};
+ });
+
+ let button = this.renderButton();
+ return (
+
+
Your choices
+
+
{button}
+
+ );
+ }
+
+ renderSpecifyChoices() {
+ let input = this.renderChoiceInputField();
+ let output = this.renderCurrentChoices();
+
+ return (
+
+ {input}
+ {output}
+
+ );
+ }
+
+ render() {
+ if (!this.state.decisions) {
+ return this.renderSpecifyChoices();
+ } else {
+ return this.renderChoosing();
}
}
- return null;
}
+
+ReactDOM.render(
, document.getElementById("root"));