Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4538304
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T14:47:38+00:00 2026-05-21T14:47:38+00:00

I have been given a task… count the number of words in the string

  • 0

I have been given a task…
“count the number of words in the string “tx_val” that have 3,4,5 or 6 characters
show these four counts on a single line separated by commas”

I have been trying multiple different loop statements but I cannot seem to get the right answer.

Here is the code I was given to work with :

<html>
<head>
<script language="javascript"> 
<!--
function fred()
{
var tx_val=document.alice.tx.value;
len_tx=tx_val.length


-->
</script>
</head>
<body>
<form name="alice">
<b>Assignment #1 Javascript</b>
<p>
The text box below is named "tx". The form is named "alice".
<p>
<input type="text" name="tx" formname="alice" size="50" value="the quick brown fox jumped over the lazy dogs back">
</form>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T14:47:38+00:00Added an answer on May 21, 2026 at 2:47 pm

    The regular expression /\b\w{3,6}\b/ matches a “word” of 3 through 6 characters in length. Now that definition of “word” may or may not suit your purposes, but it’s probably close.

    With that, you could do something like:

    var matches = theString.match(/\b\w{3,6}\b/g).length;
    

    to get the count.

    The escape “\w” matches any “word” character, which to JavaScript means alphanumerics and underscore. If you don’t like that, you could construct your own character class. For example, if you only care about words made up of letters, you could do:

    var matches = theString.match(/\b[a-zA-Z]{3,6}\b/g).length;
    

    The “\b” escape is a zero-length match for a word delineation. It matches either the start or the end of a word, without itself “consuming” any characters while doing so.

    edit — sorry I had originally mistyped a “.” in the {3,6} qualifier (and I almost did it again just now 🙂 — should have been commas.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have recently been given a task to add the ability to interact with
I have been given two different Microsoft Word document that my virus scanner has
I have been given a DLL (InfoLookup.dll) that internally allocates structures and returns pointers
I have been given the task of internationalizing a large client-server application. The remit
I have been given the task of adding functionality to an existing IIS 6.0
I have been given the task of modernizing my company's I5 based point of
I have been given the task to design a list of APIs to be
I have been given the task to fix an Embedded Operating System which is
I have been given the task of finding a replacement for a piece of
I have been given a task to enable existing Invision Power Board Forum to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.