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
Edmundo Ruiz
3,488 PointsJavaScript
/*
Write a function called countChars that accepts two parameters: a string and a character. This function should return a number representing the number of times that the character appears in string. To access the first element of a string, you can use the following syntax:
access the element at index 0
"hello"[0]; // => "h"
"dog"[0]; // => "d"
HINT: You'll also need to make use of the slice method
*/
function countChars(string, character) {
// your code here
// start solution
// end solution
}
I am doing this prep and I am completly lost.