window.onload = function(){ makeScenario = function(scenario){ //output element, that other elements are attached to let $outputElement = $("
  • ") $outputElement.attr("id", "scenarios-"+scenario.name); //Mature Content rating if(scenario.adult == true){ $adultText = $("

    (question for those over the age of 18... or those mature enough)

    "); $adultText.addClass("adult"); $outputElement.append($adultText); $outputElement.addClass("adult-scenario"); } //description $descriptionElement = $("

    " + scenario.description +"

    "); //option list $optionElement = $(""); for(option of scenario.options){ //Create radio button $inputTag = $(""); $inputTag.attr("type", "radio"); $inputTag.attr("name", "radio-"+scenario.name); //Populate list element $newOption = $("
  • "); $newOption.append($inputTag); $newOption.append(option); $optionElement.append($newOption); } //Other Question if (scenario.other){ $otherElement = $("
  • Other...
  • "); $optionElement.append($otherElement); } //Default question, always shows up $whyElement = $("

    Why would you choose this awnser?

    "); //Awnser space for the default element $whyResponseElement = $("") $whyResponseElement.attr("placeholder", "Enter response here"); //Populate outputElement $outputElement.append($descriptionElement); $outputElement.append($optionElement); $outputElement.append($whyElement); $outputElement.append($whyResponseElement); //Extra Question if(scenario.question){ $question = $("

    " + scenario.question + "

    "); $questionResponse = $(""); $questionResponse.attr("placeholder", "Enter response here"); $outputElement.append($question); $outputElement.append($questionResponse); } //Submission button $submitElement = $(""); $submitElement.attr("type", "submit"); $submitElement.append("Submit"); $outputElement.append($("

    ")); $outputElement.append($submitElement); return $outputElement; } $.getJSON("./resources/questions/scenarios.json", "", function(data){ for(const scenario of data.scenarios){ $("#scenarios").append(makeScenario(scenario)); } }); }