-
카테고리
-
세부 분야
프론트엔드
-
해결 여부
미해결
오류 질문 드립니다...
22.04.13 23:54 작성 조회수 126
0
안녕하세요
강의 듣고 해봤는데 아무리 찾아도
어디서 오류가 난건지 모르겠어서 질문 드립니다 ㅠㅠ
결과값 '땡'은 잘 나타나는데 '정답'일때만 이런 오류가 발생합니다.
<html>
<head>
<meta charset="UTF-8" />
<title>구구단</title>
<script crossorigin src="https://unpkg.com/react@16/umd/react.development.js"></script>
<script crossorigin src="https://unpkg.com/react-dom@16/umd/react-dom.development.js"></script>
<script src="https://unpkg.com/babel-standalone@6/babel.min.js"></script>
</head>
<body>
<div id="root"></div>
<script type="text/babel">
class GuGuDan extends React.Component {
constructor(props) {
super(props);
this.state = {
first: Math.ceil(Math.random() * 9),
second: Math.ceil(Math.random() * 9),
value: '',
result: ''
}; // 변하는 값 - State
}
onSubmit = (e) => {
e.preventDefault();
if (parseInt(this.state.value) === this.state.first * this.state.second) {
this.setSate({
result: '정답',
first: Math.ceil(Math.random() * 9),
second: Math.ceil(Math.random() * 9),
value: '',
});
} else {
this.setState({
result: '땡',
value: '',
});
}
};
onChange = (e) => {
this.setState({value: e.target.value});
};
render() {
return (
<div>
<div>{this.state.first} 곱하기 {this.state.second}는?</div>
<form onSubmit={this.onSubmit}>
<input type="number" value={this.state.value} onChange={this.onChange} />
<button>입력!</button>
</form>
<div>{this.state.result}</div>
</div>
);
}
}
</script>
<script type="text/babel">
ReactDOM.render(<GuGuDan />, document.querySelector('#root'))
</script>
</body>
</html>
답변을 작성해보세요.
0
답변 1