In this exercise, we count how many times the letter ‘p’ occurs in Peter Piper’s famous tongue twister:
Peter Piper picked a peck of pickled peppers.
A peck of pickled peppers Peter Piper picked.
If Peter Piper picked a peck of pickled peppers,
Where's the peck of pickled peppers Peter Piper picked?
Update file peter-piper.js, adding the correct code to
count the number of times a “P” occurs in the Peter Piper tongue twister. Be
sure to count both uppercase P
and lowercase p
characters.
- To begin, fork this repository.
- Create a new Cloud9 workspace from your new repository.
- Alternatively, you may clone your new repository to your computer.
- Modify the files and commit changes to complete your solution.
- Run
node test
to verify that all tests pass. - Push/sync the changes up to GitHub.
- Create a pull request on the original repository to turn in the assignment.
You are also welcome commit, push, and create a pull request before you’ve
completed your solution. You can ask questions or request feedback there in your
pull request. Just mention @barberboy
in your comments to get my attention.
Want to work a bit harder? Try these variations:
-
Define a function called
countOccurrences(string, char)
, which counts the number of times the characterchar
occurs in the stringstring
, then call it to find the number ofp
's in the tongue twister, like:
var counter = countOccurences(peterpiper, 'p');
. -
Instead of looking for the letter 'p', count the number of times the word
'peck'
occurs in the tongue twister. -
Try counting the occurrences of
'p'
without using afor
loop. Take a look at the other String.prototype methods for ideas.
Use git branch
(and git checkout
) to work on the extra credit on separate branches.