I don't understand why this is returning zero:
function largestOfThree (num) {
let stringyNums = num.toString();
let highest = 0;
for (let i = 0; i <= stringyNums.length - 3; i++) {
let chunk = stringyNums.slice(i, i + 3);
console.log(chunk);
if (chunk > highest) chunk = highest;
}
return highest;
}
console.log(largestOfThree(123456789));
It seems as though chunk is not getting assigned to highest. I want to assign the new chunk to highest as we're looping through the stringyNums, every time it's greater than the existing highest chunk.
The function should return 789, in this case.
chunkis a string, what doeschunk > highestactually do?.parseInt(), maybe.highest = chunkinstead ofchunk = highest