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
100 Base-T: Group of answer choices
Allisa [31]

Answer:

can run at either full- or half-duplex

Explanation:

In Computer Networking, 100Base-T also known as fast ethernet is an ethernet standard that operates at 100Mbps and can run at either full- or half-duplex.

It uses Shielded Twisted Pair (STP) cabling system.

The Variations of 100BaseT are;

- 100BaseTX

- 100BaseFX.

8 0
3 years ago
What is a “spoof” of an ad ?
kykrilka [37]
I think a spoof of an ad is the study of an ads rhetorical devices that is what I think I am not completely sure
5 0
3 years ago
Read 2 more answers
Write a program that prints the U.S. presidential election years from 1792 to present day, knowing that such elections occur eve
Naddika [18.5K]
Year = 1972
current year = 2021

while year <= current year:
print (year)
year = year + 4
8 0
2 years ago
It is okay to perform experiments without your teacher's permission. This shows creativity.
katrin2010 [14]
It would be False, because if you were to mess up it can result in something going bad.
5 0
3 years ago
What is mean by sole trading concern?​
DENIUS [597]

Answer:

trading as a whole

Explanation:

pls give brainlest almost lvled up.

6 0
3 years ago
Other questions:
  • If you want to copy text formatting from one area of your document to another area, _____.
    5·2 answers
  • Works in the public domain have copyright that are expired or abandoned true or false
    5·1 answer
  • MS Excel is a powerful spreadsheet program that helps people with complex mathematical calculations. In what ways could you use
    10·1 answer
  • What are listed in the vertical columns across the top of the Event Editor?
    5·2 answers
  • How can i change my age on my profile here bc i am 13 but i accidenlty put 2005 instead of 2006 no need to rush to answer just w
    9·2 answers
  • You are developing a Windows forms application used by a government agency. You need to develop a distinct user interface elemen
    14·1 answer
  • What are the advantages of saving files in a cloud? <br>Please help!! ​
    11·2 answers
  • De acuerdo con las generaciones de la computación, ¿Creen que estamos en la 5ta generación o aun no? y ¿por qué?
    13·1 answer
  • Constructive criticism is intended as a possible solution.
    13·1 answer
  • Place the steps for attaching a file to a message in order from top to bottom.
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!