How to change card's Back from Front using JavaScript?

74 views
Skip to first unread message

Ilmārs Cīrulis

unread,
Feb 28, 2019, 4:54:34 PM2/28/19
to mnemosyne-proj-users
Hello!
 
If I want to add some element to Back, using JavaScript in Front, is it possible?
I added an ilustration in the attachment.
 
Best wishes,
Ilmars
Screenshot_19.png

Peter Bienstman

unread,
Mar 1, 2019, 3:26:02 AM3/1/19
to mnemosyne-...@googlegroups.com

Hi,

 

I’m not sure if this will work out of the box, I suggest you try it.

 

In any case, it’ll certainly be possible to achieve this by writing a plugin for a custom Renderer and/or CardType.

 

To see how Mnemosyne assembles html, see here:

https://github.com/mnemosyne-proj/mnemosyne/blob/master/mnemosyne/libmnemosyne/renderers/html_css.py

 

Cheers,

 

Peter

--
You received this message because you are subscribed to the Google Groups "mnemosyne-proj-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mnemosyne-proj-u...@googlegroups.com.
To post to this group, send email to mnemosyne-...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mnemosyne-proj-users/9bd1ad05-d174-4773-854a-da9b6a94cd4b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ilmārs Cīrulis

unread,
Mar 2, 2019, 6:25:16 AM3/2/19
to mnemosyne-proj-users
Hello,
 
I was lazy and figured out that I can add the answer in the Front, if I simply make it invisible by using "color:white". When I need to check my answer, I can select the white text and see if I'm correct or not.
 
The Back then is left either empty, or contains some general explanation related to the question.
 
Best wishes,
Ilmars


On Friday, March 1, 2019 at 10:26:02 AM UTC+2, Peter Bienstman wrote:

Hi,

 

I’m not sure if this will work out of the box, I suggest you try it.

 

In any case, it’ll certainly be possible to achieve this by writing a plugin for a custom Renderer and/or CardType.

 

To see how Mnemosyne assembles html, see here:

https://github.com/mnemosyne-proj/mnemosyne/blob/master/mnemosyne/libmnemosyne/renderers/html_css.py

 

Cheers,

 

Peter

From: mnemosyne-...@googlegroups.com <mnemosyne-...@googlegroups.com> On Behalf Of Ilmars Cirulis
Sent: 28 February 2019 22:39
To: mnemosyne-proj-users <mnemosyne-...@googlegroups.com>
Subject: [mnemosyne-proj-users] How to change card's Back from Front using JavaScript?

 

Hello!
 

If I want to add some element to Back, using JavaScript in Front, is it possible?
I added an ilustration in the attachment.

 

Best wishes,
Ilmars

--
You received this message because you are subscribed to the Google Groups "mnemosyne-proj-users" group.

To unsubscribe from this group and stop receiving emails from it, send an email to mnemosyne-proj-users+unsub...@googlegroups.com.
To post to this group, send email to mnemosyne...@googlegroups.com.

MTSowbug

unread,
Jan 5, 2023, 2:42:24 PM1/5/23
to mnemosyne-proj-users
Sorry for replying to a years-old thread, but I have a solution to this problem. The OP had a math card that generated a math problem with JavaScript, and he wanted the randomly generated question to match the randomly generated solution. Although Mnemosyne doesn't let the front and back sides of a card pass data to each other, we can bypass the issue if the front and back use identically seeded pseudo-RNGs, e.g. by using today's date as the seed. In this manner, the front and back will always produce matching randomly generated equations.

Here is an example for a "front-to-back only" card. First, the front:


Add these numbers:
<script language="JavaScript">
//FRONT OF CARD
function Random() { seed = seed * 48271 % 2147483647; return seed; } //Lehmer MINSTD
const d = new Date();
_cardsalt = 879; //arbitrary card-specific number to stop other cards in the deck from sharing RNG
seed = d.getDate()+d.getMonth()+_cardsalt; //hash today's date
Random(); Random(); //burn the first couple random numbers

aVal=Random()%900000+100000;
bVal=Random()%900000+100000;
cVal = aVal+bVal;

document.write(aVal + " + " + bVal + " = ???<br>"); //This is the only line that differs front vs back
</script>


Then, the back:


Add these numbers:
<script language="JavaScript">
//BACK OF CARD
function Random() { seed = seed * 48271 % 2147483647; return seed; } //Lehmer MINSTD
const d = new Date();
_cardsalt = 879; //arbitrary card-specific number to stop other cards in the deck from sharing RNG
seed = d.getDate()+d.getMonth()+_cardsalt; //hash today's date
Random(); Random(); //burn the first couple random numbers

aVal=Random()%900000+100000;
bVal=Random()%900000+100000;
cVal = aVal+bVal;

document.write(aVal + " + " + bVal + " = " + cVal + "<br>"); //This is the only line that differs front vs back
</script>



I believe this method generalizes to any randomized math-based flashcards.

Peter Bienstman

unread,
Jan 6, 2023, 4:25:05 AM1/6/23
to mnemosyne-proj-users
Very nice, thanks for sharing!

Peter

Reply all
Reply to author
Forward
0 new messages