Skip to content
Tutorials Center
My learning

Topics

Lesson 37 of 38 ยท Projects and Practice

Project: Build a Simple Sentence Checker

Build a small rule-based sentence checker in JavaScript that flags double comparatives, its/it's slips, doubled words and more, and learn why real grammar tools are hard.

Programmers and writers both benefit from turning grammar rules into explicit tests. In this project you will build a small, honest tool: a rule-based checker that flags a handful of common errors from this course. It is a stand-in for the real thing. Commercial grammar tools use far larger rule sets and statistical models, and they still make mistakes.

Building it teaches you something useful: a rule you can state exactly (more + -er is always wrong) is easy to automate, while a rule that depends on meaning (Walking home, the rain started) is much harder.

Step 1: a rule is a pattern plus a message

Each rule has a regular expression to find the problem and a message that explains it.

JS Version 1: three rules

Press Run (or Ctrl + Enter) to see the console output here.

No output.

The doubled-word rule uses a back-reference: \1 means the same text that the first group matched.

Step 2: add rules from earlier lessons

Add checks for could of, alot, less before common countable plural nouns and a missing capital letter at the start. Notice the trade-off: every new rule can also produce false alarms.

JS Version 2: more rules and a score

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Why real checkers need more

Some errors need real grammatical understanding:

Error Why a pattern fails
Subject-verb agreement across a long phrase needs to find the true subject
Dangling modifiers needs to know who performs an action
Comma splices needs to know where clauses start and stop
its / it's in every case needs to understand the role of the word

A rule-based tool helps as a first pass but never replaces reading your own work.

Extend the checker yourself: add one rule for each error in your personal checklist from Practice: Edit a Paragraph, then test it on your own writing.

Check your understanding

Quick check ยท 3 questions

of 3 answered You scored / 3 ยท perfect!

  1. 1. What does the pattern /\b(\w+)\s+\1\b/ find?

    The back-reference \1 must match the same text as the first group.
  2. 2. Why can a rule-based checker produce false alarms?

    A pattern cannot tell whether a match is really an error in context.
  3. 3. Which error is hardest to detect with simple patterns?

    It depends on who performs the action, which needs deeper grammar analysis.

Summary

  • A grammar rule becomes code as a pattern plus an explanation.
  • Exact surface errors (alot, could of, doubled words) are easy to automate.
  • Meaning-based errors (dangling modifiers, agreement over distance) need more than patterns.
  • Always treat automatic checkers as helpers and read your work yourself.

Next: Grammar Review Test