Online Quiz

Hello;
We want to build a quiz whereby a 'certificate' (custom thank you bodycopy?) is issued to the user if they achieve a minimum required score.

eg: if user achieves 80% or better, they are rewarded with a certificate, or else they are shown their results and given the opportunity to redo the quiz.



My question is this: Will the module facilitate this already, or can something be written to handle this conditionally?



Can we use JavaScript to operate on keywords? I realise that most keywords are likely to be text output, but what about %quiz_total_points% and %quiz_total_available_points% are they integer/float values? Can they be operated on using JS?



Its probably messy to have to filter existing output with Javascript , rather than to call a PHP method when user submits form.



Am I making this harder than it needs to be?



thanks

Hey Rick,


I can't answer the online quiz asset questions, as I haven't yet had the chance to implement one. However, I can answer your Javascript query.



It doesn't matter how the data is stored in the database or processed by PHP, it only matters how you use the keywords in your Javascript. For example:


    

Will be parsed by Matrix and sent to the browser like this (if the quiz total points score is 6):


    

The inverted commas around the 6 in the variable make it a string, rather than an integer. This will end up with a Javascript alert with the content "56", since the + operator is concatenation when a string is involved.



This code:


    

Will be parsed by Matrix and sent to the browser like this (if the quiz total points score is 6):


    

No inverted commas mean that the variable score is holding an integer value (Javascript is a weakly typed language so we don't have to specify the type). This will result in a Javascript alert with the content "11" since the + operator when dealing only with numeric variables means addition.



So it all comes down to how you put together the Javascript.



Even if you did have the inverted commas around the value, Javascript has the function parseInt() which will get an integer value from a string. So, slightly modifying the first lot of code to include this function:


    

Will result in an alert with the content "11", since we're changing the string value into an integer and therefore performing an addition.



Hope that helps :slight_smile:

Very straight forward, thanks Casey!
We should be able to write something now ( :wink: )