Matarina Assistance Group

You might also like

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 1

// Array of questions and options

const surveyData = [
{
question: "What is your favorite color?",
options: ["Red", "Blue", "Green", "Yellow"]
},
{
question: "What is your favorite animal?",
options: ["Dog", "Cat", "Bird", "Fish"]
},
{
question: "What is your favorite season?",
options: ["Spring", "Summer", "Fall", "Winter"]
}
];

// Function to render survey questions


function renderSurvey() {
const surveyContainer = document.getElementById('survey-container');

surveyData.forEach((item, index) => {


// Create a div to hold the question and options
const questionDiv = document.createElement('div');
questionDiv.classList.add('question');

// Create and append the question text


const questionText = document.createElement('p');
questionText.textContent = item.question;
questionDiv.appendChild(questionText);

// Create and append the options as radio buttons


item.options.forEach(option => {
const optionLabel = document.createElement('label');
const optionInput = document.createElement('input');
optionInput.type = 'radio';
optionInput.name = `question-${index}`;
optionInput.value = option;
optionLabel.appendChild(optionInput);
optionLabel.appendChild(document.createTextNode(option));
questionDiv.appendChild(optionLabel);
questionDiv.appendChild(document.createElement('br'));
});

// Append the question div to the survey container


surveyContainer.appendChild(questionDiv);
});
}

You might also like