JSFiddle - React, Tailwind, and code Playground

JavaScript

function countOccurence(char, string)
{
    var counter = 0;
    
    for (var i=0; i < string.length; i++)
    {
        if (string[i] == char)
        {
            counter++;
        }
    }
    
    return counter;
}

function komischeFunktion(string)
{
    var firstpos = 0, secondpos = 0, occurence = 0, mode = 0;
    var char;
    
    for (var i=0; i < string.length; i++)
    {
        if (mode == 0)
        {
            occurence = countOccurence(string[i], string);
        
            if (occurence > 1)
            {
                firstpos = i;
                mode = 1;
		//alert(i + " " + occurence);
            }
        }
        
        else if (mode == 1)
        {
            if (string[i] == string[firstpos])
            {
                secondpos = i;
                break;
            }
        }
    }
    
    if (mode == 0)
    {
        alert("Es kommt kein Zeichen doppelt vor.");
    }
    
    else if (mode == 1)
    {
        alert("Das Zeichen " + string[firstpos] + " kommt an " + (firstpos+1) + ". und " + (secondpos+1) + ". Stelle vor.");
    }
}

komischeFunktion("EineKuhMachtMuh");