Reputation: 11
I should get printed on the page "Hello name" if age is eighteen or more. Otherwise, the page prints "You are too young". Now the page prints only "You are too young".
function HelloName() {
const [name, setName] = React.useState({name: ''});
const [age, setAge] = React.useState({age: ''});
const inputChanged = (event) => {
setName({...name, [event.target.name]:
event.target.value})
}
const formSubmitted = (event) => {
event.preventDefault();
if (age >= 18) {
alert("Hello " + name); }
else {
alert("You are too young"); }
}
Upvotes: 0
Views: 144
Reputation: 751
Age is declared as object. age.age is the right way to access your age.
Age is also declared as String. If you are going to use TS it will give you error if you assign Int to String
Upvotes: 3