Hi!
Can u please help me with this code review?
After submission of my so thought solution, the test result is giving me a bunch of errors.
The errors:
- The App component render result should not be changed
- The rendered input should have the How old are you? placeholder
- The rendered input should have the value prop
- The value prop of the rendered input should be equal to age field of the state
- The rendered input should have the onChange prop
- The onChange prop of the input should set entered string to state field age
- The Validate age button should have the onClick prop
- Enter age should be logged in console on button click if state.age is null
- You have reached adulthood in Scotland should be logged in console on button click if state.age is 16 and more
- You are not an adult in Scotland should be logged in console on button click if state.age is less then 16_
My Code
import React from 'react';
class App extends React.Component {
state = {
age: null
}
handleAgeChange = (event) => {
const { target: { value } } = event;
this.setState({ age: value });
}
handleAgeValidation = () => {
if (this.state.age < 16) {
return console.log("You are not an adult in Scotland");
} else if (this.state.age >= 16) {
return console.log("You have reached adulthood in Scotland");
} else
return console.log("Enter age")
}
render() {
const { age } = this.state;
return (
<div>
<input onChange={this.handleAgeChange} type={number} placeholder="How old are you?"
value={age} />
<button onClick={this.handleAgeValidation}>Validate age</button>
</div>
);
}
}
export default App;