Skip to content

Commit 72e09c4

Browse files
Taking X and O both turns in application
1 parent ff391d3 commit 72e09c4

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

src/index.js

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,16 @@ import React from 'react';
22
import ReactDOM from 'react-dom';
33
import './index.css';
44

5-
class Square extends React.Component {
5+
function Square(props) {
66

7-
render() {
87
return (
98
<button className="square"
10-
onClick = {() => this.props.onClick()}
9+
onClick = {props.onClick}
1110
>
12-
{this.props.value}
11+
{props.value}
1312
</button>
1413
);
15-
}
14+
1615
}
1716

1817
class Board extends React.Component {
@@ -21,13 +20,17 @@ class Square extends React.Component {
2120
super(props);
2221
this.state = {
2322
squares: Array(9).fill(null),
23+
xIsNext:true,
2424
}
2525
}
2626

2727
handleClick(i){
2828
const squares = this.state.squares.slice();
29-
squares[i]='X';
30-
this.setState({squares:squares});
29+
squares[i]=this.state.xIsNext?'X':'O';
30+
this.setState({
31+
squares:squares,
32+
xIsNext:!this.state.xIsNext,
33+
});
3134
}
3235
renderSquare(i) {
3336
return (
@@ -39,7 +42,7 @@ class Square extends React.Component {
3942
}
4043

4144
render() {
42-
const status = 'Next player: X';
45+
const status = 'Next player: '+ (this.state.xIsNext ? 'X' : 'O');
4346

4447
return (
4548
<div>

0 commit comments

Comments
 (0)