Daily Quiz Owner

jQuery(document).ready(function($) {
// Function to generate the quiz
window.generateQuiz = function() {
// Get the input values
const question = $(‘#question’).val();
const optionA = $(‘#optionA’).val();
const optionB = $(‘#optionB’).val();
const optionC = $(‘#optionC’).val();
const optionD = $(‘#optionD’).val();

// Validate inputs
if (!question || !optionA || !optionB || !optionC || !optionD) {
alert(“Please fill in all fields!”);
return;
}

// Populate the quiz card
$(‘#quizQuestion’).text(question);
$(‘#quizOptionA’).text(optionA);
$(‘#quizOptionB’).text(optionB);
$(‘#quizOptionC’).text(optionC);
$(‘#quizOptionD’).text(optionD);

// Hide the generator and show the quiz card
$(‘#quizGenerator’).hide();
$(‘#quizCard’).show();
};

// Handle form submission
$(‘#quizForm’).on(‘submit’, function(e) {
e.preventDefault(); // Prevent default form submission

// Get form data
const selectedAnswer = $(‘input[name=”answer”]:checked’).val();
const userEmail = $(‘#userEmail’).val();

// Validate email
if (!userEmail) {
alert(“Please enter your email!”);
return;
}

// Log the data (for now)
console.log({
answer: selectedAnswer,
email: userEmail
});

// Here, you can add an AJAX call to send the data to your email
// For example, using EmailJS or a WordPress REST API endpoint
alert(“Quiz submitted! Check the console for the response.”);

// Optionally, reset the form and show the generator again
$(‘#quizForm’)[0].reset();
$(‘#quizCard’).hide();
$(‘#quizGenerator’).show();
});
});