Welcome, Guest
You have to register before you can post on our site.

Username
  

Password
  





Search Forums

(Advanced Search)

Latest Threads
Passed Exam
Forum: CCNP ENCOR 350-401 Forum
Last Post: brownhorse
11-16-2024, 01:25 AM
» Replies: 1
» Views: 457
AN324
Forum: Answer this question
Last Post: help_desk
11-13-2024, 10:19 AM
» Replies: 1
» Views: 154
AN413
Forum: Answer this question
Last Post: help_desk
11-08-2024, 01:11 PM
» Replies: 1
» Views: 189
AND60
Forum: Answer this question
Last Post: help_desk
11-04-2024, 10:37 AM
» Replies: 1
» Views: 176
and64
Forum: Answer this question
Last Post: help_desk
11-04-2024, 10:11 AM
» Replies: 1
» Views: 192
AN600
Forum: Answer this question
Last Post: help_desk
10-26-2024, 09:34 AM
» Replies: 1
» Views: 262
AN401
Forum: Answer this question
Last Post: help_desk
10-23-2024, 10:49 AM
» Replies: 1
» Views: 301
Just Passed! Corrected La...
Forum: CCNP ENARSI 300-410 Forum
Last Post: jupertino
10-14-2024, 04:15 AM
» Replies: 1
» Views: 485
Anyone pass recently usin...
Forum: CCNP ENARSI 300-410 Forum
Last Post: jupertino
10-14-2024, 04:02 AM
» Replies: 1
» Views: 1,013
Packet Tracer Labs
Forum: Site News & Issues
Last Post: forumsupport
10-10-2024, 09:40 AM
» Replies: 3
» Views: 796

 
  Randomize Multiple Choice Questions
Posted by: jupertino - 09-08-2024, 04:27 PM - Forum: CCNP ENARSI 300-410 Forum - No Replies

Hi everyone, so I had a problem - I found that I was memorizing the position of the answer, rather than the answer itself. As a result, I'd like to share a script I made that randomizes order of the answers in the multiple choice questions. You'll need to download a chrome plugin to use it, and I never encourage anyone to copy code off of the internet without reading it manually first. Please read the code for yourself, it's very short. 

This script does the following:

It selects all elements with the class quesContainer, which corresponds to your question containers.
For each question, it selects all <p> elements, which contain the answer options.
It shuffles the order of these options.
Finally, it re-appends the shuffled options back to the question container.

1. Install the Tampermonkey extension for Chrome (if you haven't already).
2. Open Tampermonkey in Chrome and create a new script.
3. paste the script (after you've vetted it) into the script editor.
4. Save the script.
5. Go to chrome://extensions/ and click "developer mode" on the top right in order to enable script injection. Mine didn't work until I did this. 

Script is below:
---------------------------------------------------------------------------------------------------------------------------------------

// ==UserScript==
// @name         Improved Randomize Multiple Choice Options for How2Pass
// @namespace    http://tampermonkey.net/
// @version      0.4
// @description  Randomize the order of multiple choice options for How2Pass website with improved logging
// @match        https://www.how2pass.com/emembers/enarsi410/onlinetest/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    let hasRun = false;

    function shuffleArray(array) {
        for (let i = array.length - 1; i > 0; i--) {
            const j = Math.floor(Math.random() * (i + 1));
            [array[i], array[j]] = [array[j], array[i]];
        }
    }

    function randomizeOptions() {
        if (hasRun) {
            console.log("Script has already run once, skipping...");
            return;
        }

        console.log("Starting randomization process...");
        const questions = document.querySelectorAll('.quesContainer');
        console.log(`Found ${questions.length} questions`);

        questions.forEach((question, index) => {
            const options = Array.from(question.querySelectorAll('p > label.black'));
            console.log(`Question ${index + 1} has ${options.length} options`);

            if (options.length > 0) {
                const optionsContainer = options[0].parentNode.parentNode;
                const originalOrder = options.map(opt => opt.textContent.trim());
                console.log(`Original order for Q${index + 1}:`, originalOrder);

                shuffleArray(options);
                options.forEach(option => optionsContainer.appendChild(option.parentNode));

                const newOrder = Array.from(question.querySelectorAll('p > label.black')).map(opt => opt.textContent.trim());
                console.log(`New order for Q${index + 1}:`, newOrder);

                if (JSON.stringify(originalOrder) !== JSON.stringify(newOrder)) {
                    console.log(`Question ${index + 1} options were successfully randomized`);
                } else {
                    console.log(`Warning: Question ${index + 1} options remained in the same order`);
                }
            } else {
                console.log(`No options found for question ${index + 1}`);
            }
        });

        console.log("Randomization process complete");
        hasRun = true;
    }

    // Wait for the page to load and then run the script
    window.addEventListener('load', function() {
        console.log("Page loaded, waiting 3 seconds before randomizing...");
        setTimeout(randomizeOptions, 3000);
    });
})();

---------------------------------------------------------------------------------------------------------------------------------------

Line-by-Line Explanation of the Multiple-Choice Randomizer Script

---------------------------------------------------------------------------------------------------------------------------------------
[align=left]// ==UserScript==
// @name         Improved Randomize Multiple Choice Options for How2Pass
// @namespace    http://tampermonkey.net/
// @version      0.4
// @description  Randomize the order of multiple choice options for How2Pass website with improved logging
// @match        https://www.how2pass.com/emembers/enarsi410/onlinetest/*
// @grant        none
// ==/UserScript==
---------------------------------------------------------------------------------------------------------------------------------------
This is the metadata block for Tampermonkey. It defines the script's name, version, description, and which websites it should run on.

---------------------------------------------------------------------------------------------------------------------------------------
(function() {
    'use strict';
---------------------------------------------------------------------------------------------------------------------------------------
This creates an Immediately Invoked Function Expression (IIFE) to avoid polluting the global scope. 'use strict' enables strict mode for better error catching.

---------------------------------------------------------------------------------------------------------------------------------------
let hasRun = false;
---------------------------------------------------------------------------------------------------------------------------------------
This variable keeps track of whether the script has already run to prevent multiple executions.

---------------------------------------------------------------------------------------------------------------------------------------
function shuffleArray(array) {
        for (let i = array.length - 1; i > 0; i--) {
            const j = Math.floor(Math.random() * (i + 1));
            [array[i], array[j]] = [array[j], array[i]];
        }
    }
---------------------------------------------------------------------------------------------------------------------------------------
This function implements the Fisher-Yates shuffle algorithm to randomize the order of elements in an array.

---------------------------------------------------------------------------------------------------------------------------------------
function randomizeOptions() {
        if (hasRun) {
            console.log("Script has already run once, skipping...");
            return;
        }
---------------------------------------------------------------------------------------------------------------------------------------
This is the main function that randomizes the options. It first checks if the script has already run to avoid repeated randomization.

---------------------------------------------------------------------------------------------------------------------------------------
console.log("Starting randomization process...");
        const questions = document.querySelectorAll('.quesContainer');
        console.log(`Found ${questions.length} questions`);
---------------------------------------------------------------------------------------------------------------------------------------
This logs the start of the process and finds all question containers on the page.

---------------------------------------------------------------------------------------------------------------------------------------
questions.forEach((question, index) => {
            const options = Array.from(question.querySelectorAll('p > label.black'));
            console.log(`Question ${index + 1} has ${options.length} options`);
---------------------------------------------------------------------------------------------------------------------------------------
For each question, this finds all the answer options and logs how many there are.

---------------------------------------------------------------------------------------------------------------------------------------
if (options.length > 0) {
                const optionsContainer = options[0].parentNode.parentNode;
                const originalOrder = options.map(opt => opt.textContent.trim());
                console.log(`Original order for Q${index + 1}:`, originalOrder);
---------------------------------------------------------------------------------------------------------------------------------------
If options are found, it stores the original order for logging purposes.

---------------------------------------------------------------------------------------------------------------------------------------
shuffleArray(options);
                options.forEach(option => optionsContainer.appendChild(option.parentNode));
---------------------------------------------------------------------------------------------------------------------------------------
This shuffles the options and reappends them to the container, effectively randomizing their order.

---------------------------------------------------------------------------------------------------------------------------------------
const newOrder = Array.from(question.querySelectorAll('p > label.black')).map(opt => opt.textContent.trim());
                console.log(`New order for Q${index + 1}:`, newOrder);
---------------------------------------------------------------------------------------------------------------------------------------
This logs the new order of options after randomization.

---------------------------------------------------------------------------------------------------------------------------------------
if (JSON.stringify(originalOrder) !== JSON.stringify(newOrder)) {
                    console.log(`Question ${index + 1} options were successfully randomized`);
                } else {
                    console.log(`Warning: Question ${index + 1} options remained in the same order`);
                }
---------------------------------------------------------------------------------------------------------------------------------------
This checks if the order actually changed and logs the result.

---------------------------------------------------------------------------------------------------------------------------------------
} else {
                console.log(`No options found for question ${index + 1}`);
            }
        });
---------------------------------------------------------------------------------------------------------------------------------------
If no options were found for a question, this logs a message.

---------------------------------------------------------------------------------------------------------------------------------------
console.log("Randomization process complete");
        hasRun = true;
    }
---------------------------------------------------------------------------------------------------------------------------------------
This logs the completion of the process and sets the hasRun flag to true.

---------------------------------------------------------------------------------------------------------------------------------------
window.addEventListener('load', function() {
        console.log("Page loaded, waiting 3 seconds before randomizing...");
        setTimeout(randomizeOptions, 3000);
    });
})();
---------------------------------------------------------------------------------------------------------------------------------------
This adds an event listener to run the randomization function 3 seconds after the page has fully loaded and closes the IIFE.
---------------------------------------------------------------------------------------------------------------------------------------



Let me know if you have any questions. I hope this helps anyone else!

Print this item

  Network Access - QID:AN303
Posted by: kfav85 - 09-08-2024, 03:24 PM - Forum: General - Replies (1)

Option 3 has a typo that needs to be corrected: Enable 802.1x Layer 2 security and set "me" Comeback timer to 10.

Print this item

  QID:AN461
Posted by: kfav85 - 09-08-2024, 03:05 PM - Forum: General - Replies (1)

The switches do not display MAC addresses to determine which switch becomes the root bridge.

Print this item

Lightbulb Packet Tracer Labs
Posted by: forumsupport - 09-06-2024, 08:36 PM - Forum: Site News & Issues - Replies (3)

We are adding the Packet Tracer Activity-based Lab Simulations to our CCNA 200-301 product. Please use this thread to post any issues/comments about these labs.

Print this item

  OSPF Configuration Sim #3
Posted by: djwalker1 - 09-06-2024, 02:59 PM - Forum: Answer this question - Replies (1)

The instructions are not correct for this lab. It seems they are for  OSPF Configuration Sim #2. It makes mention of a switch but there is not a switch in the topology simulation.

Print this item

  QID:AN420
Posted by: kfav85 - 09-05-2024, 05:00 PM - Forum: General - Replies (1)

The exhibit shows that the switch has a mac address table entry for PC1 but on port Fa0/2 not Fa0/1, which is where it is connected on the switch. PC2 is connected to Fa0/2. So the question is kind of misleading. Shouldn't the table show Fa0/1 as the port for PC1's dynamically learned mac address?

Print this item

Photo QID:AN819 Network Access
Posted by: kfav85 - 09-05-2024, 01:35 PM - Forum: General - Replies (1)

Which interface is used to send traffic to the destination?

No exhibit button exists to fully understand the question.

Print this item

  New CCNA V1.1
Posted by: sjacobs - 08-19-2024, 03:07 PM - Forum: General Discussion - Replies (3)

There is a new CCNA version 1.1 coming very soon. Will your material cover these updates??
Thanks

Print this item

  Exams
Posted by: rubecentro - 08-16-2024, 12:16 PM - Forum: General Discussion - Replies (3)

Hello everyone I was wondering if the website support team can removal of outdated answer in their current section to be repalced by updated answer provided into the update section .

Print this item

  QID:AN614
Posted by: jedib21 - 08-10-2024, 07:45 PM - Forum: Exam Experience - Replies (1)

The explanation doesnt match the question given.

Print this item