Skip to content
This repository has been archived by the owner on Feb 27, 2021. It is now read-only.

Commit

Permalink
add support for randomly-generated text-based multiple choice questions
Browse files Browse the repository at this point in the history
  • Loading branch information
developerace committed Aug 20, 2017
1 parent 7924476 commit e4507a4
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
7 changes: 7 additions & 0 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,13 @@
}
break;

case "random":
for ($questionNumber=0; $questionNumber <= 3; $questionNumber++) {
$options = $questionObject["options"];
$choices[] = $options[mt_rand(0, count($options)-1)];
}
break;

default:
# code...
break;
Expand Down
2 changes: 1 addition & 1 deletion index.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<label class="multiplechoiceIMG"><input type="radio" form="continue" name="multiplechoice" required><img class="multiplechoiceimage" src="{$value}"></label><br>
{/foreach}
</form>
{elseif $multiplechoicetype eq "text"}
{elseif $multiplechoicetype eq "text" or "random"}
<form class="multiplechoice">
{foreach from=$choices key=$key item=$value}
<label class="multiplechoice"><input type="radio" form="continue" name="multiplechoice" required>{$value}</label><br>
Expand Down
10 changes: 8 additions & 2 deletions questions.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@
array(
// array(
// "question" => "How cute is this cat?", //REQUIRED
// "type" => "randomFromAPI", //REQUIRED. can be "randomfromAPI" or "text"
// "type" => "randomFromAPI", //REQUIRED. can be "randomfromAPI", "random" or "text"
// "API" => "http://random.cat/meow", //required if type is "randomfromAPI"
// "option" => "Option 1" //required for each option if type is "text"
// "Option 1" //required for each option if type is "text"
// "options" => Array() //required if type = random
// ),
array(
"question" => "Which of these cats is cuter?",
Expand All @@ -26,6 +27,11 @@
"question" => "Which of these dogs is cuter?",
"type" => "randomFromAPI",
"API" => "https://random.dog/woof.json"
),
array(
"question" => "Which emoji do you like better?",
"type" => "random",
"options" => array("👌","😂","🙄","❤️","☺️","😘","😉","😜","😔","😳","😑","😊","🎉","😇","","🤷","🏻","🙃","😅","💃","🏻","🏼","⭐️","💥")
)
),
//rating scale (2)
Expand Down

0 comments on commit e4507a4

Please sign in to comment.