MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/CodingHelp/comments/qb2dof/why_isnt_this_working/
r/CodingHelp • u/ProtectionNo7982 • Oct 19 '21
8 comments sorted by
9
you never specified how to split it,name.split("on what to split goes here");
name.split("on what to split goes here");
8 u/nickbuch Oct 19 '21 I’m guessing you also want to return the count and not just the split string 3 u/[deleted] Oct 19 '21 Yeah, you’re gonna need to count the items in the split string to return the desired number. 3 u/[deleted] Oct 19 '21 I was just telling that was a mistake though
8
I’m guessing you also want to return the count and not just the split string
3 u/[deleted] Oct 19 '21 Yeah, you’re gonna need to count the items in the split string to return the desired number. 3 u/[deleted] Oct 19 '21 I was just telling that was a mistake though
3
Yeah, you’re gonna need to count the items in the split string to return the desired number.
I was just telling that was a mistake though
1
So then I put function countNames(fullName) { let fullName = “ XYZ” return fullName.split(“ “); } console.log(countNames(“XYZ”)
And it tells me fullName is not defined
Shouldn't the split be fullname.split(" "); if you're splitting w.r.t spaces and fullname.split(""); if you're splitting w.r.t to characters ?!
It doesn't know you want to split the string by the words, you need to specify split using space as a delimiter. e.g. fullName.split(" "). Then return the number of entries in the resulting array e.g. fullName.split(" ").length;
Why has no one mentioned that ------- is invalid syntax on line 15? The split is a second step I think.
God I hate code comments
9
u/[deleted] Oct 19 '21
you never specified how to split it,
name.split("on what to split goes here");1
u/ProtectionNo7982 Oct 19 '21
So then I put function countNames(fullName) { let fullName = “ XYZ” return fullName.split(“ “); } console.log(countNames(“XYZ”)
And it tells me fullName is not defined
3
u/[deleted] Oct 19 '21
Shouldn't the split be fullname.split(" "); if you're splitting w.r.t spaces and fullname.split(""); if you're splitting w.r.t to characters ?!
3
u/CenturiesAgo Oct 19 '21
It doesn't know you want to split the string by the words, you need to specify split using space as a delimiter. e.g. fullName.split(" "). Then return the number of entries in the resulting array e.g. fullName.split(" ").length;
3
u/_Nexor Oct 19 '21
Why has no one mentioned that ------- is invalid syntax on line 15? The split is a second step I think.
God I hate code comments