JavaScript Regular Expressions in JavaScript Reformatting User Input Reformatting Text

Dan Warren
Dan Warren
9,125 Points

Regular Expressions in JavaScript Coding Challenge

I keep getting the error "Bummer: SyntaxError: app.js: Unexpected token `` (18:3)". How do I fix that?

function reformatName(text) {
  const rawName = /^(\w+)\s(\w+)$/;

  // Type your answer on line 5, below:

function formatName(text) {
  const newText = /'$2, $1'/;
  return text.replace(rawName, newText);

const form = document.querySelector("form");
const input = form.querySelector("input");
const reformatted = document.getElementById("reformatted");

form.addEventListener("submit", e => {
  reformatted.textContent = reformatName(input.value);
<!DOCTYPE html>

    <title>DOM Manipulation</title>
<link rel="stylesheet" href="style.css" />

    <div id="content">
            <label for="name">Enter your first and last name, please.</label>
            <br />
            <input type="text" id="name" name="name">
            <button type="submit">Reformat</button>
            <h2>Reformatted name:</h2>
                <p id="reformatted"></p>
    <script src="app.js"></script>