Beginner : JS MCQ probleme


#1

Hello,
Sorry for my english. I’m french :blush:
It’s not my first work with Hype, but it’s my first with javascript …AAAAAAArghhh.
I’m trying to create a MCQ. I download a quiz model on the forum. And try to edit it…but i dont talk JS, i am a donkey.
At the end of the MCQ, i need to find the highest score (anwsers A, B and C) and then go to a specific page. There is 3 pages at the end. One for A, one for B, one for C

Could somebody help me ?

quizdemo.hype.zip (459.7 KB)


(Jonathan Deutsch) #2

To clarify, you are looking to see which is the highest number between the variables of window.quizScoreA, window.quizScoreB, and window.quizScoreC? And then have the user go to a specific page?

You’d do code like:

if(window.quizScoreA >= window.quizScoreB && window.quizScoreA >= window.quizScoreC) {
   hypeDocument.showSceneNamed("Resultat A");
} else if(window.quizScoreB >= window.quizScoreA && window.quizScoreB >= window.quizScoreC) {
   hypeDocument.showSceneNamed("Resultat B");
} else if(window.quizScoreC >= window.quizScoreA && window.quizScoreC >= window.quizScoreB) {
   hypeDocument.showSceneNamed("Resultat C");
} 

This has a bias towards going to A, then B, then C if there is equality on the scores. Also you may need to adjust the scene names. We probably can’t write all the code for you, so it is recommended to pick up some JavaScript to extend this further.


#3

Super !
Thanks a lot Jonathan.
It works. I just had to delete one “if” !
else if (window.quizScoreB >= window.quizScoreA && window.quizScoreB >= window.quizScoreC).

Et voila
The file is herequizdemo-V2.hype.zip (592.4 KB)


(Jonathan Deutsch) #4

Oh sorry! that’s what I get for not checking my code close enough!