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
Anyone help pls ? Complete the code below to add css to make the background of the web page orange.
pochemuha

Answer:

In HTML file

<body style="background-color:orange;">

Or

In CSS file

body {

background-color: orange;

}

7 0
3 years ago
Choose the term that best matches the definition.
Y_Kistochka [10]

Answer: it’s network protocol

Explanation:

4 0
2 years ago
Which heading function is the biggest?<br> 1. h1<br> 2. h2<br> 3. h3
sattari [20]

Answer:

h3

Explanation:

sub to Thicc Panda on YT

6 0
3 years ago
Read 2 more answers
In which of the following scenarios would you use the Redo function?
MakcuM [25]
D. <span>You have just used the Undo function to delete a paragraph, and you want that paragraph back.</span>
6 0
3 years ago
98 points possible
joja [24]

A programming language is not used to talk from human to human. It is used to talk from a human to a computer. Computers are very dumb compared to us, so they need to be taught or spoken to in simple terms. Asking them something complex is far beyond their understanding, as they cannot learn anything beyond what has already been taught to them. Using print: “Hello, World” is the way to tell them to do stuff way less complex than when we say ‘write the words Hello, World on the screen’. A programming language is also not very easy to create. Talking to a computer in a dumb way reduces the process to make a new language for the computer to understand.

6 0
3 years ago
Read 2 more answers
Other questions:
  • Of the different IRT roles, the _______________ is head of the team and issues the ultimate call regarding how to respond to an
    15·1 answer
  • Which of the following filenames is acceptable on both Windows and Mac<br> operating systems?
    9·1 answer
  • Jim is in the market for a car that will last for the next 10 years and has saved up some money for the purpose of a car. What’s
    6·1 answer
  • Students are studying the effects of beach pollution by counting populations of seagulls at two different beach locations. One l
    7·1 answer
  • Write a program to calculate and return total surface area of a box using FUNCTION _END FUNCTION.​
    15·1 answer
  • The computer has had far-reaching effects on our lives.how has the computer effected your life?
    8·1 answer
  • Lisa has a section of her document that she would like to include in the index. Which option should Lisa choose?
    12·1 answer
  • a rule that states each foreign key value must match a primary key value in the other relation is called the
    5·1 answer
  • Why is simplicity important in navigation design?
    13·1 answer
  • At the heart of every computing device is a(n) _______________, which is usually a single, thin wafer of silicon and tiny transi
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!