Not the most efficient answer, but it is!
const findStrongestNumber = () => { let interval = [ parseInt(document.querySelector("#num1").value), parseInt(document.querySelector("#num2").value) ]; let numStrength = [0, 0]; for(let i = 0; i < interval.length; i++) { let num = interval[i]; while ((num % 2) !== 1) { num/=2; numStrength[i]++; } } let answer = 0; if(numStrength[0] > numStrength[1]) { answer = interval[0]; } else if (numStrength[1] > numStrength[0]) { answer = interval[1] } else { if(interval[0] < interval[1]) { answer = interval[0]; } else { answer = interval[1]; } } document.querySelector("#answer").innerHTML = answer; }
CodePen
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Not the most efficient answer, but it is!
CodePen