This allows you to get the length of a string:
String.length - JavaScript | MDN[
^]
Then you can use this little bit trick to test whether a number is odd or even:
function isOdd(n)
{
return n & 1 == 1;
}
The rest is just a matter of an
if .. else
block to implement the logic.