-
-
Save MeliAlbu/275b252f46b4b702c67c0785cfa96319 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Sum extends Component { | |
constructor(props) { | |
super(props); | |
this.state = { | |
firstValue: "", | |
secondValue: "", | |
sumVar: "", | |
}; | |
} | |
handleFirstInput(e) { | |
this.setState({ | |
firstValue: e.target.value, | |
}); | |
} | |
handleSecondInput(e) { | |
this.setState({ | |
secondValue: e.target.value, | |
}); | |
} | |
handleClick() { | |
var number1 = this.state.firstValue; | |
var number2 = this.state.secondValue; | |
var Sum = parseInt(number1) + parseInt(number2); | |
this.setState({ sumVar: Sum }); | |
} | |
render() { | |
return ( | |
<div> | |
<input type="text" onChange={(e) => this.handleFirstInput(e)} /> | |
<input type="text" onChange={(e) => this.handleSecondInput(e)} /> | |
<button onClick={() => this.handleClick()}>Sumar</button> | |
<p>La suma es {this.state.sumVar}</p> | |
</div> | |
); | |
} | |
} | |
export default Sum; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment