[テストコード/Lv.1]推測コーラ


[質問]



[プール]-JavaScript

function solution(num) {
    let answer = 0;
    
    while(true){
        if(num == 1 ) break;
        
        num % 2 == 0 ? 
            ( num /= 2, answer++) :
            ( num = num * 3 + 1, answer++)
        
        if(answer == 500) { answer = -1; break; }
    }
    
    return answer;
}

[結果]



成功