JSFiddle - React, Tailwind, and code Playground
JavaScript
function findNextSquare(sq) {
// Return the next square if sq if a perfect square, -1 otherwise
let sqrt = Math.sqrt(sq);
const isInt = (sqrt ^ 0) === sqrt;
if (isInt) {
return Math.pow(++sqrt, 2);
} else {
return -1;
}
}
console.log(findNextSquare(121));