On the Javascript part you see how the score is calculated and how it will be display on the site, but i want the score that comes out inserted my flask app. So I'm able to insert the score into my MySql database. Sorry for my bad English.
Javascript:
// Computes score and returns a paragraph element to be displayed
function displayScore() {
var score = $('<p class="quizvraag">', {id: 'question'});
var numCorrect = 0;
for (var i = 0; i < selections.length; i++) {
if (selections[i] === questions[i].correctAnswer) {
numCorrect++;
}
}
score.append('You got ' + numCorrect + ' questions out of ' +
questions.length + ' right!!!');
return score;
}`
Flask:
@app.route('/quiz')
def quiz():
startquiz()
DbLayer = DbClass()
vragen = DbLayer.getQuizVraag()
list_vraag = [vragen]
print(vragen)
return render_template('quiztestjs.html', vraag=vragen, list_vraag=list_vraag)
MySql query:
def setDataToDatabase(self, Score1):
# Query met parameters
sqlQuery = "INSERT INTO tbl_score (Score1) VALUES ('{param1}')"
sqlCommand = sqlQuery.format(param1=Score1)
self.__cursor.execute(sqlCommand)
self.__connection.commit()
self.__cursor.close()