Skip to content
This repository has been archived by the owner on Feb 8, 2018. It is now read-only.

Modularity #28

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
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
7 changes: 4 additions & 3 deletions src/controllers/question.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ export async function checkAnswer(ctx) {
userId: user.id
},
})
const answers=JSON.parse(question.answer)
for(var i in preAnswered){
if (preAnswered[i].useranswer in JSON.parse(question.answer))
if (preAnswered[i].useranswer in answers)
correctAttempts+=1
// else{
// wrongAttempts+=1
Expand All @@ -34,7 +35,7 @@ export async function checkAnswer(ctx) {
await UserAnswer.create(
{ questionId: question.id, userId: user.id, useranswer: ctx.body.answer}
)
if (correctAttempts==0 && (ctx.body.answer in JSON.parse(question.answer))) {
if (correctAttempts==0 && (ctx.body.answer in answers)) {
const { user } = ctx.state
if (user.maxUnlock == qno) {
user.maxUnlock += 1
Expand All @@ -43,7 +44,7 @@ export async function checkAnswer(ctx) {
}
ctx.body = { response: true }
}
else if(correctAttempts==1) ctx.body = { response: "Already attempted" }
else if(correctAttempts==1 && (ctx.body.answer in answers)) ctx.body = { response: "Already attempted" }
Copy link
Member

@ironmaniiith ironmaniiith Sep 30, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do not put this second condition && (ctx.body.answer in answers), as we would like to send the response as Already attempted irrespective of whether the current answer is right or wrong

else ctx.body = { response: false }

}
Expand Down