Snippet Preview

<style>
    body {
        font-family: Arial, sans-serif;
        max-width: 700px;
        margin: auto;
        background: #f9f9f9;
    }
    .quiz-container {
        background: white;
        padding: 20px;
        border-radius: 10px;
        box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.1);
    }
    h2, h3 {
        text-align: center;
        color: #333;
    }
    .question {
        margin-bottom: 15px;
        font-weight: bold;
    }
    .options label {
        display: block;
        padding: 5px;
        cursor: pointer;
    }
    .timer {
        text-align: center;
        font-size: 18px;
        font-weight: bold;
        color: red;
    }
    #submitQuiz {
        display: block;
        width: 100%;
        padding: 10px;
        background: #007bff;
        color: white;
        border: none;
        border-radius: 5px;
        font-size: 16px;
        cursor: pointer;
        margin-top: 15px;
    }
    #submitQuiz:hover {
        background: #0056b3;
    }
    #result {
        text-align: center;
        font-size: 20px;
        margin-top: 20px;
        font-weight: bold;
        color: green;
    }
</style>

<div class="quiz-container">
    <h2>Career Aptitude Test</h2>
    <p class="timer">Time Remaining: <span id="time">15:00</span></p>
    <form id="quizForm">
        <?php 
        $questions = [
            "Which activity excites you the most?",
            "What kind of environment do you enjoy working in?",
            "If you had to volunteer, where would you prefer?",
            "What do you find most satisfying?",
            "Which of these careers sounds most exciting?",
            "How do you handle a crisis?",
            "Which skill do you think you excel at?",
            "If a friend gets injured, what’s your first response?",
            "When working in a team, what role do you prefer?",
            "How do you like to learn new things?",
            "What is your strongest personality trait?",
            "Which word best describes you?",
            "How do you prefer to solve problems?",
            "What kind of work excites you?",
            "How do you feel about high-pressure situations?",
            "What excites you most about your future job?",
            "Where do you see yourself working in 5 years?",
            "If you had to choose one, what would it be?"
        ];

        $options = ["A" => "Nursing", "B" => "Hotel Management", "C" => "Construction", "D" => "Healthcare", "E" => "Paramedical"];

        foreach ($questions as $index => $question) {
            echo "<div class='question'><p>" . ($index + 1) . ". " . $question . "</p>";
            echo "<div class='options'>";
            foreach ($options as $key => $value) {
                echo "<label><input type='radio' name='q$index' value='$key' required> $value</label>";
            }
            echo "</div></div>";
        }
        ?>
        <button type="submit" id="submitQuiz">Submit</button>
    </form>
    <div id="result"></div>
</div>

<script>
    let timeLeft = 900; // 15 minutes (900 seconds)
    let timerElement = document.getElementById("time");

    function startTimer() {
        let timer = setInterval(() => {
            let minutes = Math.floor(timeLeft / 60);
            let seconds = timeLeft % 60;
            timerElement.textContent = `${minutes}:${seconds < 10 ? '0' : ''}${seconds}`;
            if (timeLeft <= 0) {
                clearInterval(timer);
                document.getElementById("quizForm").submit();
            }
            timeLeft--;
        }, 1000);
    }

    document.addEventListener("DOMContentLoaded", startTimer);

    document.getElementById("quizForm").addEventListener("submit", function(event) {
        event.preventDefault();

        let answers = document.querySelectorAll("input[type='radio']:checked");
        let scores = { "A": 0, "B": 0, "C": 0, "D": 0, "E": 0 };

        answers.forEach(answer => {
            scores[answer.value]++;
        });

        let maxScore = Math.max(...Object.values(scores));
        let recommendedField = Object.keys(scores).find(key => scores[key] === maxScore);

        let fieldMapping = {
            "A": "Nursing",
            "B": "Hotel Management",
            "C": "Construction",
            "D": "Healthcare",
            "E": "Paramedical"
        };

        document.getElementById("result").innerHTML = "Recommended Career: <strong>" + fieldMapping[recommendedField] + "</strong>";
    });
</script>

<?php
return ob_get_clean();

}

function register_aptitude_test_shortcode() {
add_shortcode(‘career_aptitude_test’, ‘career_aptitude_test’);
}
add_action(‘init’, ‘register_aptitude_test_shortcode’);
?>