Word counter

  • React
  • Exercises
  • Word counter

React exercise number 5

  • JSX
  • useState

Word counter

Let's build a React app to count words!

Quick start

Start with this code as a boilerplate for the exercise.

Exercise

Step 1:

Make that when the user clicks on the "Delete sentence" button, all the text in the input is deleted.

Step 2:

Show the number of words in the entered sentence. Whenever the user writes a new sentence in the input, the number of words must be updated in real-time. To get the individual words of a string, you can try using the split method, for example:

const words = "This is my dog".split(" ");
// words = ["This", "is", "my", "dog"]

Step 3:

Show the number of words starting with the letter "A" or "a" (uppercase or lowercase).

Step 4:

Show the number of words that end with the letter "Z" or "z" (uppercase or lowercase).

Step 5:

Show the first letter of the sentence.

Step 6:

Show the last letter of the sentence.

Step 7:

Show the sentence in reverse. For example for the phrase "I am learning React" it would show "tcaeR gninrael ma I".