Tell us what’s happening:
Describe your issue in detail here.
my code is running well but i can’t pass the challenge
why? Your code so far
function largestPrimeFactor(number) {
let n = 0;
let s = true
for(let i = 2; i < number; i++){
if(number % i == 0){
s = false
n = number / i
break;
}
}
if(s == false){
largestPrimeFactor(n)
}else{
console.log(number)
return number
}
}
largestPrimeFactor(13195);
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36
Challenge: Project Euler - Problem 3: Largest prime factor
No. Your base case has a return value. But since your recursive case has no return value, that doesn’t get propegated up the call stack and you are returning ‘undefined’.
yeah you are right it is returning undefined
thank you
what do you think i should do here?
is my code invalid?
or can i fix it?
what should i return there?
oh ok…
can you tell me what it is?
i won’t look at it now
im going to take a little break then try again
but if i wasn’t able to find what it is i will look here XD