1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
maksim [4K]
3 years ago
11

Write a function named countWords that reads in a line of text into a string variable, counts and returns the number of words in

the line. For simplicity assume that the line entered only has characters and spaces.
Computers and Technology
1 answer:
algol133 years ago
3 0

Answer:

function countWords(sentence) {

return sentence.match(/\S+/g).length;

}

const sentence = 'This sentence  has five  words ';

console.log(`"${sentence}" has ${countWords(sentence)} words` );

Explanation:

Regular expressions are a powerful way to tackle this. One obvious cornercase is that multiple spaces could occur. The regex doesn't care.

You might be interested in
What is the best free game designing program for windows
Nadusha1986 [10]
Python, Unity 3D, C++Notepad
8 0
3 years ago
Name the tools and materials used in electrical installation job below.​
kow [346]
Voltage tester, Circuit finder, Screwdrivers and nut drivers specific to electricians, Pliers, measuring tape
8 0
3 years ago
Hymter. Wants to workin The Energy career field with electrical energy
m_a_m_a [10]

Answer: what is the question

Explanation:

3 0
3 years ago
An Excel file can be saved as a Web page. T or F
Katen [24]

Answer:

True

Explanation:

5 0
3 years ago
Read 2 more answers
All of the following are types of telescope except Hubble space telescope electron telescope radio telescope reflecting telescop
Hunter-Best [27]
Radio telescope is the answer
3 0
4 years ago
Other questions:
  • Nadia has inserted an image into a Word document and now would like to resize the image to fit the document better. What is the
    6·1 answer
  • Which product is made using bacteria?<br>O A. Maple syrup<br>O B. Cork<br>O C. Latex<br>D. Yogurt​
    12·1 answer
  • What happens in the process represented by the flowchart ?
    14·1 answer
  • A diagram of a flow chart to find the average of 10 numbers​
    7·1 answer
  • pharmaceutical company is using blockchain to manage their supply chain. Some of their drugs must be stored at a lower temperatu
    5·2 answers
  • Which component of cpu controls the overall operation of computer..​
    11·1 answer
  • Select the items below that are examples of things that could use the smart card technology.
    7·1 answer
  • Arrays are commonly used to store data items. Arrays can be managed in ways that fill, iterate over, add to, and delete items fr
    14·1 answer
  • What are the advantages of using an electronic database to store information?
    15·1 answer
  • What are the four components of security documentation?
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!