Malachi-M / peter-piper

An exercise for inspecting strings using .length and .charAt()

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Peter Piper Exercise

Join the chat at https://gitter.im/unioncollege-webtech/peter-piper

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?

Description

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.

Completing and submitting 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.

Extra Credit

Want to work a bit harder? Try these variations:

  • Define a function called countOccurrences(string, char), which counts the number of times the character char occurs in the string string, then call it to find the number of p's in the tongue twister, like:
    var counter = countOccurances(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 a for 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.

References

About

An exercise for inspecting strings using .length and .charAt()

License:ISC License


Languages

Language:JavaScript 100.0%