From be1246aee47e4697653660aeef3df5a8e284d29a Mon Sep 17 00:00:00 2001 From: Jaisel Rahman Date: Sun, 8 Sep 2019 18:24:18 +0530 Subject: [PATCH] Allow different possible answers --- src/questions.js | 20 ++++++++++---------- src/views/GoogleIt.vue | 32 ++++++++++++++++++++++---------- 2 files changed, 32 insertions(+), 20 deletions(-) diff --git a/src/questions.js b/src/questions.js index 2b92092..9a72659 100644 --- a/src/questions.js +++ b/src/questions.js @@ -10,28 +10,28 @@ export default [ type: "text", name: "Error", title: 'Name a 5 letter word which has three consonants all the same and two different vowels. Every now and then you see this while running a windows 95/98 on your PC.', - correctAnswer: 'Error', + correctAnswer: 'error', }] }, { questions: [{ type: "text", name: "Big Mac", title: 'What do you get when you cross a hamburger with a computer ?', - correctAnswer: 'Big Mac', + correctAnswer: ['big mac', 'bigmac'], }] }, { questions: [{ type: "text", name: "Firewall", title: 'I am a Barrier that acts as a security system to protect trusted computer system. Who am I ?', - correctAnswer: 'Firewall', + correctAnswer: 'firewall', }] }, { questions: [{ type: "text", name: "Intranet", title: 'Basically a private internal internet specific to an organisation or a group. Who am I ?', - correctAnswer: 'Intranet', + correctAnswer: 'intranet', }] }, { @@ -39,7 +39,7 @@ export default [ type: "text", name: "Computer Disc", title: 'I come in square package but I am round, I contain lots of Information for your Computer, handle me carefully, What am I ?', - correctAnswer: 'Compact Disc', + correctAnswer: ['compact disc', 'cd'], }] }, { @@ -47,7 +47,7 @@ export default [ type: "text", name: "Home Page", title: 'You can see me usually at the starting point of an organisation website. Who am I ?', - correctAnswer: 'Home Page', + correctAnswer: ['homepage', 'home page'], }] }, { @@ -55,7 +55,7 @@ export default [ type: "text", name: "Saas", title: 'I am a software distribution model where software applications are centrally hosted and licensed on subscription basis. Who am I ?', - correctAnswer: 'Saas', + correctAnswer: ['software as a service', 'saas'], }] }, { @@ -63,7 +63,7 @@ export default [ type: "text", name: "ACCRINTM", title: 'Find the MS Excel function to return accrued interest for a security that pays interest at maturity is', - correctAnswer: 'ACCRINTM', + correctAnswer: 'accrintm', }] }, { @@ -71,7 +71,7 @@ export default [ type: "text", name: "C++", title: 'My name has a post Increment but not Preincrement. Every Software Engineer knows my name', - correctAnswer: 'C++', + correctAnswer: 'c++', }] }, { @@ -79,7 +79,7 @@ export default [ type: "text", name: "Pointer", title: "I provide way to find some other, my name ends with 'R', I am not a palindrome find me who I am ?", - correctAnswer: 'Pointer', + correctAnswer: 'pointer', }] }, ] \ No newline at end of file diff --git a/src/views/GoogleIt.vue b/src/views/GoogleIt.vue index 1db58d8..b9b1b24 100644 --- a/src/views/GoogleIt.vue +++ b/src/views/GoogleIt.vue @@ -51,7 +51,7 @@ export default { this.isSignedIn = firebaseAuth.currentUser != null; firebaseAuth.onAuthStateChanged(u => { this.isSignedIn = !!u && u.currentUser !== null; - if(!this.isSignedIn) { + if (!this.isSignedIn) { window.localStorage.removeItem(this.storageName); } }); @@ -61,9 +61,9 @@ export default { var res = { currentPageNo: survey.currentPageNo, data: survey.data, - timeSpent: survey.currentPage.timeSpent, + timeSpent: survey.currentPage.timeSpent }; - + window.localStorage.setItem(this.storageName, JSON.stringify(res)); }, loadState(survey) { @@ -79,15 +79,18 @@ export default { }, mounted() { this.survey.onComplete.add(survey => { - firebase.firestore().collection('google-it').doc(firebaseAuth.currentUser.email).set( - { + firestore + .collection("google-it") + .doc(firebaseAuth.currentUser.email) + .set({ name: firebaseAuth.currentUser.email, - score: this.survey.getCorrectedAnswerCount(), - } - ).catch(e => { - console.log(e); - }); + score: this.survey.getCorrectedAnswerCount() + }) + .catch(e => { + console.log(e); + }); + console.log({ score: this.survey.getCorrectedAnswerCount() }); clearInterval(this.timerId); this.saveState(survey); }); @@ -106,6 +109,15 @@ export default { options.text = `Remining Time: ${sender.maxTimeToFinishPage - sender.currentPage.timeSpent}s`; }); + + this.survey.onIsAnswerCorrect.add((sender, options) => { + let question = options.question; + if (Array.isArray(question.correctAnswer)) { + let answers = question.correctAnswer; + let value = question.value == null ? "" : question.value.toLowerCase(); + options.result = answers.find(t => t == value) != null; + } + }); } };