-
Notifications
You must be signed in to change notification settings - Fork 12
Modularity #28
base: master
Are you sure you want to change the base?
Modularity #28
Conversation
src/routes/comment.js
Outdated
}, | ||
{ | ||
method: 'get', | ||
path: '/:qno/getall', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dont put getall at the back. A GET request already implies that
src/controllers/question.js
Outdated
@@ -10,24 +10,40 @@ export async function get(ctx) { | |||
} | |||
|
|||
export async function checkAnswer(ctx) { | |||
//var wrongAttempts=0 | |||
var correctAttempts=0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use let
instead of var
src/controllers/question.js
Outdated
}, | ||
}) | ||
for(var i in preAnswered){ | ||
if (preAnswered[i].useranswer in JSON.parse(question.answer)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Store the output of JSON.parse(question.answer) in a variable outside the for loop and use it wherever required. It will avoid recomputing it everytime.
src/controllers/question.js
Outdated
@@ -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" } |
There was a problem hiding this comment.
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
Fixes #30 |
No description provided.