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
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
9
u/[deleted] Oct 19 '21
you never specified how to split it,
name.split("on what to split goes here");