code to check if number is prime number
I will just be looking at your prime function.

You got the right idea, but you missed some edge cases, and it can also be optimized. 2 and 3 are prime but return false, since halfNum starts at 1, and do...while loops always run at least once. 1 is not prime but return true, along with some negative numbers. The easiest way to handle this is just to check for this special case at the start of the function.

if(n &lt;= 1) return false;


You are checking for divisibility with all numbers between 2 and half the input, which is good. But it seems a bit confusing to me when you use a do...while loop and counting down, instead of just counting up with a good old for loop.

for(let i = 2; i &lt;= halfNum; i++)


But we can optimize this, since we only need to check up to the square root of the number. For any divisible number larger than the square root, there will also be a divisible number lower than the square root. For example, 100 is divisible by 20, but also 5, since 20*5=100. I'm also going to pre-calculate it and rename halfNum as that name doesn't fit anymore.

const limit = Math.sqrt(num);


The final function looks like this.

function isPrime(num) {
    if(num &lt;= 1) return false;
    const limit = Math.floor(Math.sqrt(num));
    for(let i = 2; i &lt;= limit; i++) {
        if(num % i === 0) return false;
    }
    return true;
}