Simple function returning 'undefined' value

前端 未结 6 724
春和景丽
春和景丽 2020-12-28 19:28

This is the function I am currently working on:

function getSmallestDivisor(xVal) {    

    if (xVal % 2 === 0) {
        return 2;
    } else if (xVal % 3          


        
6条回答
  •  一生所求
    2020-12-28 20:12

    if (xSqrt % 1 === 0) {
        return getSmallestDivisor(xSqrt); // missing return here
    } else {
        return xVal;
    }
    

    Demo: Fiddle

提交回复
热议问题