Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Will Potter
7,577 PointsType Error: not a function
So I'm working on writing a function for a coding challenge on another website, and I ran in to this error when testing out my (unfinished) code: "TYPE ERROR: strOne.split() is not a function"
function CountingMinutesI(str) {
//split times into two strings
var strOne = str.slice(0, str.indexOf("-"));
var strTwo = str.slice(str.indexOf("-")+1, str.length+1)
//convert to array
if (/am/.test(strOne)) {
strOne -= "am";
var arrOne = strOne.split(":");
}
else if (/pm/.test(strTwo)) {
strTwo -= "pm";
var arrTwo = strTwo.split(":");
}
//convert to military time
}
Will Potter
7,577 PointsWill Potter
7,577 PointsNever mind, I figured it out. Although you can use += to add content to a string, you can't use -= to remove content from a string. When I did, it changed strOne's type from string to NaN. I still don't really understand why. But anyway, if this ever happens to you, just use the replace method. In my case, strOne.replace("am", ""). You can replace whatever value in your string with nothing, which is the same as removing it.