Not sure why my code is failing these tests: 2. When I click the element with the id of “break-decrement”, the value within id=“break-length” decrements by a value of 1, and I can see the updated value, 3. When I click the element with the id of “break-increment”, the value within id=“break-length” increments by a value of 1, and I can see the updated value, 4. When I click the element with the id of “session-decrement”, the value within id=“session-length” decrements by a value of 1, and I can see the updated value, 5. When I click the element with the id of “session-increment”, the value within id=“session-length” increments by a value of 1, and I can see the updated value.
Clock (not finished)
class Clock extends Component {
constructor(props) {
super(props);
this.state = {break:5,
session:25}
this.handleClick = this.handleClick.bind(this);
}
handleClick(evt){
const id= evt.target.id;
let breakvar= this.state.break;
let sessionvar= this.state.session;
if (id==="break-increment" && breakvar<=59){
this.setState((state) => ({
break: this.state.break +1}));}
else if (id==="break-decrement" && breakvar>0){
this.setState((state) => ({
break: this.state.break -1}));}
else if (id==="session-increment" && sessionvar<=59){
this.setState((state) => ({
session: this.state.session +1}));}
else if(id==="session-decrement" && sessionvar>0){
this.setState((state) => ({
session: this.state.session -1}));}
}
render() {
return(
<div id="container">
<Display break={this.state.break} session={this.state.session}/>
<p id="break-label">Break length</p>
<Button onClick={this.handleClick} id="break-increment"/>
<Button onClick={this.handleClick} id="break-decrement"/>
<p id="session-label">Session length</p>
<Button onClick={this.handleClick} id="session-increment" />
<Button onClick={this.handleClick} id="session-decrement"/>
<Button onClick={this.handleClick} id="start_stop"/>
<Button onClick={this.handleClick} id="reset"/>
</div>
)
}
}export default Clock
Display
const Display = (props) => {
return (
<div>
<h1 id="break-length"> {props.break} </h1>
<h2 id="session-length">{props.session} </h2>
<p id="time-left">{props.session}</p>
<p id="timer-label">Session</p>
</div>
)};