Project Requirements:

The project requirement for TypeScript word count project is, the user will enter a English paragraph and all that is needed is to just to implement counting characters and words without whitespaces.

Analysis:

Implementation of TypeScript word count project is, a function that counts the words without whitespaces in an English paragraph.

Shebang code:

The line #!/usr/bin/env node in TypeScript code is called a shebang. It tells the operating system to use the Node.js interpreter to run the script. This is a common convention in Node.js scripts.

Import modules:

The `inquirer` module is imported from the `inquirer` package. You need to install the inquirer module first using the npm install inquirer command.

Function startLoop:

Prompts the user to continue the loop.

Steps:

  1. Await the result of the getSentence() function.
  2. Prompt the user to continue the loop using the inquirer.prompt() function.
  3. Repeat steps 1 and 2 while the user selects “Yes”.

Function getSentence:

Prompts the user to enter a sentence and prints the word count.

Steps:

  1. Prompt the user to enter a sentence using the inquirer.prompt() function.
  2. Trim the whitespace from the user’s input.
  3. Count the words in the user’s input using the wordCount() function.
  4. Print the word count to the console.

Function wordCount:

Counts the number of words in a string.

Steps:

  1. Split the string into words using the split() method.
  2. Log the words to the console for debugging purposes (optional).
  3. Return the length of the array of words.

 

Ahmer Arman

Best Laptop

JII Stores

GitHub Link