Find the next perfect square

Codewars question

Complete the findNextSquare method that finds the next integral perfect square after the one passed as a parameter. Recall that an integral perfect square is an integer n such that sqrt(n) is also an integer.

If the parameter is itself not a perfect square, than -1 should be returned. You may assume the parameter is positive.


function findNextSquare(sq){
    var root1;
    var nextroot;
    if(Math.sqrt(sq)%1 ===0){
         root1=Math.sqrt(sq)
         nextroot=root1+1
    }else{
        return -1;
    }
    return nextroot*nextroot;
}

// Sample tests
findNextSquare(9) // 16
findNextSquare(16) // 25
findNextSquare(121) // 144
findNextSquare(625) // 676
findNextSquare(319225) // 320356
findNextSquare(15241383936) // 15241630849