diff --git a/src/ComfortIssues.js b/src/ComfortIssues.js index b3aacc522cd80188a41acc7d582dd8aecbfe96f1..61019ea50429d4ba2c54a16d81ad201ab38b3b11 100644 --- a/src/ComfortIssues.js +++ b/src/ComfortIssues.js @@ -8,6 +8,8 @@ export default class ComfortIssues extends React.Component { this.state = { answerIds: this.props.answer, }; + // AnswerId for 'THEY DON'T COMPLAIN AT ALL' option + this.noComplaints = 31 this.names = { tooHot: 'They complain it\'s too hot', tooCold: 'They complain it\'s too cold', @@ -32,17 +34,23 @@ export default class ComfortIssues extends React.Component { chooseAnswer = (answerId) => { let answerIds = this.state.answerIds - if (answerIds.includes(answerId)) { - answerIds = answerIds.filter(id => id !== answerId); - } else { - answerIds.push(answerId); + if (answerId === this.noComplaints) { + answerIds = answerIds.includes(answerId) ? [] : [answerId]; + } + else { + answerIds = answerIds.filter(id => id !== this.noComplaints); + if (answerIds.includes(answerId)) { + answerIds = answerIds.filter(id => id !== answerId); + } else { + answerIds.push(answerId); + } } this.setState({ answerIds }); } render() { let message = ""; - if (this.state.answerIds.length > 0) { + if (!this.state.answerIds.includes(this.noComplaints) && this.state.answerIds.length > 0) { message = (