Straighterline.com provides self-paced college level courses that transfer into some degree programs at brick & mortar universities. The courses are only eligible for transfer credit at a few higher-ed institutions, and they're a great option for self-motivated learners working on knocking out pre-requisites.
I completed several Straighterline courses when exploring another degree program. I like using Anki flashcards to reinforce my learning, and I wanted a way to quickly convert my graded Straighterline quizzes and exams into flashcards.
Here's the workflow that I used to convert graded Straighterline quizzes & exams into flashcards:
1. Run the script in the browser console
Running the following JavaScript in the browser console should copy the questions and answers to your clipboard in a comma-separated-value format.
const questions = [...document.querySelectorAll('.qtext')].map((q) => q.innerText);
const answers = [...document.querySelectorAll('.answer')];
const answersText = answers.map((answer) => {
const isCorrect = !!answer.querySelector('.correct');
if (isCorrect) {
return answer.querySelector('.correct').querySelector('label').innerText;
}
const incorrectText = answer.querySelector('.incorrect').querySelector('label').innerText;
return '🚨 INCORRECT: ' + incorrectText ?? 'ANSWER NOT FOUND';
});
const cleanString = (str) => str.replaceAll(',', ' ');
const questionAndAnswers = questions.reduce((acc, question) => {
return `${acc}\n${cleanString(question)}, ${cleanString(answersText.shift())}`;
}, ``);
console.log(questionAndAnswers);
copy(questionAndAnswers);
2. Paste the script's output into a .csv file
The copied questions & answers should look something like this:
...
In the context of operant conditioning identify a true statement about negative reinforcement.,b. It means following a behavior with the removal of something.
Which of the following statements about B. F. Skinner is FALSE?,🚨 INCORRECT: a. Skinner conducted many of his studies with animals as opposed to human subjects.
...
Take the copied Q & A and paste them into a new .csv file.
3. Import the .csv file into an Anki deck
Import the .csv file into Anki, making sure to select comma
as the Field separator
:
Conclusion
That's it!
The script/worflow is a bit of a hack, but it saved me some time. Maybe it will help someone else facing a similar problem 🤷🏻♂️
I last tried this in summer of 2023, and it's dependent on Straighterline's HTML remaining unchanged, so the script may require tweaking going forward. YMMV