Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,9 @@ class FormView extends Component {
type: "GET",
success: (result) => {
this.setState({ categories: result.categories })
return;
},
error: (error) => {
alert('Unable to load categories. Please try your request again')
return;
}
})
}
Expand All @@ -50,11 +48,9 @@ class FormView extends Component {
crossDomain: true,
success: (result) => {
document.getElementById("add-question-form").reset();
return;
},
error: (error) => {
alert('Unable to add question. Please try your request again')
return;
}
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,11 @@ class QuestionView extends Component {
questions: result.questions,
totalQuestions: result.total_questions,
categories: result.categories,
currentCategory: result.current_category })
return;
currentCategory: result.current_category
})
},
error: (error) => {
alert('Unable to load questions. Please try your request again')
return;
}
})
}
Expand Down Expand Up @@ -66,12 +65,11 @@ class QuestionView extends Component {
this.setState({
questions: result.questions,
totalQuestions: result.total_questions,
currentCategory: result.current_category })
return;
currentCategory: result.current_category
})
},
error: (error) => {
alert('Unable to load questions. Please try your request again')
return;
}
})
}
Expand All @@ -91,12 +89,11 @@ class QuestionView extends Component {
this.setState({
questions: result.questions,
totalQuestions: result.total_questions,
currentCategory: result.current_category })
return;
currentCategory: result.current_category
})
},
error: (error) => {
alert('Unable to load questions. Please try your request again')
return;
}
})
}
Expand All @@ -112,7 +109,6 @@ class QuestionView extends Component {
},
error: (error) => {
alert('Unable to load questions. Please try your request again')
return;
}
})
}
Expand Down Expand Up @@ -141,7 +137,7 @@ class QuestionView extends Component {
key={q.id}
question={q.question}
answer={q.answer}
category={this.state.categories[q.category]}
category={this.state.categories[q.category]}
difficulty={q.difficulty}
questionAction={this.questionAction(q.id)}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ import $ from 'jquery';

import '../stylesheets/QuizView.css';

const questionsPerPlay = 5;
const questionsPerPlay = 5;

class QuizView extends Component {
constructor(props){
super();
this.state = {
quizCategory: null,
previousQuestions: [],
previousQuestions: [],
showAnswer: false,
categories: {},
numCorrect: 0,
Expand All @@ -26,11 +26,9 @@ class QuizView extends Component {
type: "GET",
success: (result) => {
this.setState({ categories: result.categories })
return;
},
error: (error) => {
alert('Unable to load categories. Please try your request again')
return;
}
})
}
Expand Down Expand Up @@ -68,19 +66,17 @@ class QuizView extends Component {
guess: '',
forceEnd: result.question ? false : true
})
return;
},
error: (error) => {
alert('Unable to load question. Please try your request again')
return;
}
})
}

submitGuess = (event) => {
event.preventDefault();
const formatGuess = this.state.guess.replace(/[.,\/#!$%\^&\*;:{}=\-_`~()]/g,"").toLowerCase()
let evaluate = this.evaluateAnswer()
const evaluate = this.evaluateAnswer()
this.setState({
numCorrect: !evaluate ? this.state.numCorrect : this.state.numCorrect + 1,
showAnswer: true,
Expand All @@ -90,7 +86,7 @@ class QuizView extends Component {
restartGame = () => {
this.setState({
quizCategory: null,
previousQuestions: [],
previousQuestions: [],
showAnswer: false,
numCorrect: 0,
currentQuestion: {},
Expand Down Expand Up @@ -138,7 +134,7 @@ class QuizView extends Component {

renderCorrectAnswer(){
const formatGuess = this.state.guess.replace(/[.,\/#!$%\^&\*;:{}=\-_`~()]/g,"").toLowerCase()
let evaluate = this.evaluateAnswer()
const evaluate = this.evaluateAnswer()
return(
<div className="quiz-play-holder">
<div className="quiz-question">{this.state.currentQuestion.question}</div>
Expand All @@ -152,7 +148,7 @@ class QuizView extends Component {
renderPlay(){
return this.state.previousQuestions.length === questionsPerPlay || this.state.forceEnd
? this.renderFinalScore()
: this.state.showAnswer
: this.state.showAnswer
? this.renderCorrectAnswer()
: (
<div className="quiz-play-holder">
Expand Down