0

I want to know how to get the array index values dynamically.

Here I am customizing the quizy-fillintheblanks.master.zip files used in my coding:

<script>
  $('#tutorial-fillblank').quizyFillBlank({
    textItems:['The first president of the United States of America is', '. The longest serving president of the country is ', '. He was succeeded by ', ', who led the country till the end of the Second World War. The first afro-american to be elected for this position is', '.'],
    anItems:['John Kennedy', 'Franklin Roosevelt', 'George Washington', 'Ronald Reagan', 'Harry Truman', 'Richard Nixon', 'Barack Obama' ], 
    anItemsCorrect:[2,1,4,6],
    blockSize:150
  });
</script>

In above coding textItems are questions and anItems are answers, and anItemCorrect is the array index value for anItems.

In that coding I am customizing values I'm getting from a database into questions and answers. Here I don't know how to pass anItemCorrect value dynamically:

<script>
  $('#tutorial-fillblank').quizyFillBlank({
    textItems:[<?php foreach($question as $article)  { echo "'".$article->question."',";}?>],
    anItems:[<?php foreach($question as $article)
    {$a[]=$article->answer;}
    $arr=$a; shuffle($arr); foreach($arr as $ans => $val) {echo "'".$val."',";} ?> ], 
    anItemsCorrect:[<?php foreach($arr as $ans => $val) { echo "'".$ans."',";} ?>],
    blockSize:150
  });
</script>

How can I use jquery.inArray() to dynamically choose whether an answer is right or wrong?

1

1 Answer 1

0

You can't, because you shuffle your questions, so you don't know what order the answers are in.

Instead of doing that, use an associated php array mapping question=>answer. Then you can shuffle and order will be maintained.

Sign up to request clarification or add additional context in comments.

1 Comment

How could I use associative php array mapping here because i am getting questions in $article->question and answers as $article->answers getting whole array values. In this how could i use associative array

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.