Script – 22-55 Feb 1
I'm trying to run the function till
b.length === 1
and then return b
What am I doing wrong? it returns undefined
30 Replies
because you don't return
recall(b)
call?wow you could probably stand to name your variables a bit better 🙂
Like ![thistbh](https://cdn.discordapp.com/emojis/871942722003533904.png)
![thistbh](https://cdn.discordapp.com/emojis/871942722003533904.png)
i meant this
![](https://answer-overflow-discord-attachments.s3.amazonaws.com/938207510152769546/unknown.png)
😂
I was just rushing and giving it similar var names
I tried that but still got undefined
is
b.length === 1
condition ever met?yes
so
recall
at that case should return non-undefined b
variable, because it surely is array/string with length property equal to 1I'll look at my code ![yy](https://cdn.discordapp.com/emojis/230122396923723777.png)
![yy](https://cdn.discordapp.com/emojis/230122396923723777.png)
to be clear, you mean that
superDigit
returns undefined or recall
?
and are you sure that recursion ends sometime, not throws call stack exceeded error?Return the last line
return recall(b)
@ScriptOkay so I am finally exceeding the call stack
How do I manage this
Yeah then your base condition is never being met
It is actually
b becomes 3
that's length of 1
If you would properly hit the base condition you wouldn’t exceed the call stack
Are you calling length on a number? Does that give you the amount of digits?
yes b is an integer
What does the length of 0 return
0.length
![KomodoHype](https://cdn.discordapp.com/emojis/796647947521622036.png)
And
3.length
?
I’m on phone so I can’t verify myselfUnknown User•3y ago
Message Not Public
Sign In & Join Server To View
Are you perhaps assuming that you can call
length
on a number without actually trying it out?Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
Yeah
same thing
invalid
So why are you calling
length
on a number 😛
Turn it to a string first![shocked](https://cdn.discordapp.com/emojis/723676848093134886.png)
Don’t just assume code will work like you expect it to, you need to test and confirm even the smallest things heh
Yeah all good
ayee
still gettin undefined
wait am I supposed to return
![coolcry](https://cdn.discordapp.com/emojis/911482713180082217.png)
recall(b)
in recall()?
Because I did now and it workedYeah you are indeed
Since it will evaluate to a number, but that number needs to be returned to the caller
This question has an answer! Thank you for helping 😄
If you have a followup question, you may want to reply to this thread so other members know they're related. https://discord.com/channels/102860784329052160/565213527673929729/938205834796744794
This thread hasn’t had any activity in 12 hours, so it’s now locked.
Threads are closed automatically after 12 hours. If you have a followup question, you may want to reply to this thread so other members know they're related. https://discord.com/channels/102860784329052160/565213527673929729/938205834796744794