Explain how this code to find the nth prime works

Hello! I’m a beginner at learning Javascript and found a code to find the nth prime number given a user’s input (ex: find the 10th prime number). However, I was wondering if someone could explain explain why/how this Javascript code works?

Thanks!

function start()
{
    findNthPrime();
}

function findNthPrime()
{
    var n = readInt();
    var num = 1;
    var count = 0;
    
    while (count < n)
    {
        num = num+1;
        for (var i = 2; i <= num; i++)
        {
            if (num % i == 0)
            {
                break;
            }
        }
        if (i == num)
        {
            count = count+1;
        }
    }
    println("Your nth prime is: " + num);
}