Anki cloze – type answer

Last Updated on October 9, 2023

Cloze is a special note’s type. You can skip a word or some words or whole sentence. Programm show you a sentence with skipped places and you think, which words have to match.

In my cards I could not only remember, but also type words. It is great exercise for translation from native to foreign language.

All posts about Anki
Part 1. Studying
Part 2. Editing a deck and notes
Part 3. Creating new notes
Part 4. Editing templates
Part 6. Add a pronunciation

It gives a lot:

  • the word is placed in context
  • you can train forms and prepositions
  • you can train meanings that are lost when we train a word without context. Many verbs have two or more very different meanings, each of which is often used in speech. But when studing a word, we study the first meaning well, and the second is often not learned or is forgotten.
  • you can study idioms

This guide has been updated for Anki’s new design. The old version is not much different. For more important differences, the old version is hidden under spoilers. In the new version, you can click the “Downgrade” button in the “Profiles” window. But in terms of design, the new version is better.

In contrast to the standard form, I added a code for typing words to the cloze cards. The standard form assumes only turning the card over. In the previous post, we added such a feature, but there was a default code that does not work in the cloze. Here I had to search in various forums, from where I got the working code. Don’t ask me what it means – I just copied it with copy-paste.

Set up a Anki cloze template

1. On the page that lists the decks, go to Tools / Manage Note Types. There we press Add: Cloze.

Anki cloze

Select “Fields” on the right. In the window that opens, click Add and enter the names of the fields that we need.

I have three fields. One German, in which I make a gap (Satz_deu). The second is native language, from which I translate (Satz_Muttersprache). And then there is the third (Basic_word). It does not participate in studing, but it is necessary so that in the overview the cards are shown not by the first word of the sentence, but by the main word. This is bequem for sorting.

Anki cloze

Basic information about templates read here: Editing templates

When we have entered the names of the fields, go to the Cards. There is only one card here and it looks like this.

Please note that the code should contain the field name that you entered in the previous step.

Old Version
Anki cloze / Anki Lücken mit Tippen

New version Anki

Anki cloze type answer / Anki Lücken mit Tippen

Since not all the code is visible in the scan, I copy:

<div style='font-family: Arial; font-size: 20px;'>{{muttersprache}}<br><br><br></div>

{{type:cloze:deu}}{{cloze:deu}}

<script type="text/javascript">
var fields = [];
function updateMain()
{
    ///Updates the primary "typeans" textbox with the results of each textbox.
    ///Only used if there are multiple cloze deletions.
    var textbox = document.getElementById("typeans");
    var str = "";
    var previous = "";
    var maxLength = fields.length;
    for (var i = 0; i < maxLength; i++)
    {
        //add the comma beforehand instead of afterwards, this avoids the need to explicitly handle consolidating two consecutive fields with the same value.
        var toAdd = fields[i].value;
        var addComma = (i != 0 && toAdd != previous);
        if(addComma)
        {
            str += ", ";
        }

        if(toAdd == previous)
            continue; //do nothing if the same data is consecutive.
        str += toAdd;
        previous = toAdd;
    }

    textbox.value = str;
    return true;
}
mungeCloze = function()
{
    var textbox = document.getElementById("typeans")
    //clozes are blue elements of: [...] which we want to remove.
    var clozes = document.getElementsByClassName("cloze");

    if(textbox == null || clozes.length == 0)
        return;

    var needsWork = (clozes.length > 1);

    fields = [];
    if(!needsWork)
    {
        var cloze = clozes[0];
        if(cloze != null)
        {
            textbox.removeAttribute("class")

            var container = cloze.parentNode;
            container.insertBefore(textbox, cloze);
            container.removeChild(cloze);
            textbox.style.display = ""; //make visible.
        }

    }
    else
    {
        //Clone the textbox and insert it before the deletions: "[...]".
        var length = clozes.length;
        var originalTextbox = textbox;
        for (var i = 0; i < length; i++)
        {
            var cloze = clozes[i];
            if (cloze == null)
                continue;

            var textboxToReplace = originalTextbox.cloneNode(true);
            textboxToReplace.id = "typeans" + i;
            textboxToReplace.onkeyup = updateMain;

            var container = cloze.parentNode;
            container.insertBefore(textboxToReplace, cloze);
            fields.push(textboxToReplace);
        }
      
        //Once we've handled each cloze, remove it from the list so it will not be modified again.
        while(clozes.length > 0)
        {
            var toRemove = clozes[0];
            toRemove.parentNode.removeChild(toRemove);
        } 

        //We hide the textbox here. If we did this beforehand then .clone() would transfer this to the new textboxes.
        originalTextbox.style.display = "none";
    }
}
mungeCloze();
window.setTimeout(mungeCloze, 1000);
</script>

You can read in the topics how to fill out the attachments (Anlage) to the tax return and who is supposed to apply it #German tax return

It was Front Template.

Now Back Template

Anki cloze type answer / Anki Lücken mit Tippen

And Styling:

Anki cloze type answer / Anki Lücken mit Tippen
.card
{
font-family: arial;
font-size: 20px;
text-align: center;
color: black;
background-color: white;
}
.cloze
{
    font-weight: bold;
    color: blue;
}
#typeans { width: 450px; }
center { display:inline; }
typeGood { background: lightgreen; }
.typeBad { background: pink; }
.typeMissed { background: pink; }

Make a note

Template is finished. Now we make a notes. We can copy sentences from all unsere textbooks or online-exercises.

How you can add a note – read here.

I gave in this post only a couple of images. Not forget to check type of note, deck, tags.

After you have written the sentence, highlight the place you want to skip. And click three dots. You see brackets {{ }} and c1:: This means, that you made a gap. Pink field – because I took a sentence, that I already have. Duplicates are shown below.

Anki cloze type answer Anki make a note / Anki Lücken mit Tippen

If I make two gaps, for example if I have a Perfekt form, then second gap will have a c2:: This must be changed to c1::, otherwise this card will be shown two times: first with first gap, then with second gap.

Anki cloze type answer / Anki Lücken mit Tippen

This is how it will look during training. Errors are highlighted in pink.

Anki cloze type answer / Anki Lücken mit Tippen Lükentext
Anki cloze type answer / Anki Lücken mit Tippen

Other posts about Anki – #anki.
Part 1. Studying
Part 2. Editing a deck and notes
Part 3. Creating new notes
Part 4. Editing templates
Part 6. Add a pronunciation

Do you enjoy the site without cookies and maybe without ads? This means that I work for you at my own expense.
Perhaps you would like to support my work here.
Or
Cookie settings change: round sign bottom left

Leave a comment

Email is not compulsory