Build a Customer Complaint Form - Build a Customer Complaint Form

Tell us what’s happening:

My code is running fine but i can’t seem to pass test 30 ,please help me out

Your code so far

<!-- file: index.html -->
<!DOCTYPE html>
<html lang="en">

<head>
    <title>Customer Complaint Form</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="styles.css">
</head>

<body>
    <h1>Complaint Form</h1>
    <form id="form">
        <fieldset id="personal-info">
            <div>
                <label for="full-name">Full Name:</label>
                <input type="text" id="full-name" name="full-name" placeholder="John Doe" required>
            </div>

            <div>
                <label for="email">Email Address:</label>
                <input type="email" id="email" name="email" placeholder="example@domain.com">
            </div>
        </fieldset>
        <hr>
        <fieldset id="product-info">
            <div>
                <label for="order-no">Order No:</label>
                <input type="text" id="order-no" name="order-no" placeholder="2024######">
            </div>
            <div>
                <label for="product-code">Product Code:</label>
                <input type="text" id="product-code" name="product-code" placeholder="XX##-X###-XX#">
            </div>
            <div>
                <label for="quantity">Quantity:</label>
                <input type="number" id="quantity" name="quantity" min="1">
            </div>
        </fieldset>

        <fieldset id="complaints-group">
            <legend>Complaint Reason:</legend>
            <div>
                <input type="checkbox" id="damaged-product" name="complaint" value="damaged-product">
                <label for="damaged-product">Damaged Product</label>
            </div>

            <div>
                <input type="checkbox" id="nonconforming-product" name="complaint" value="nonconforming-product">
                <label for="nonconforming-product">Nonconforming Product</label>
            </div>

            <div>
                <input type="checkbox" id="delayed-dispatch" name="complaint" value="delayed-dispatch">
                <label for="delayed-dispatch">Delayed Dispatch</label>
            </div>

            <div>
                <input type="checkbox" id="other-complaint" name="complaint" value="other">
                <label for="other-complaint">Other</label>
            </div>
        </fieldset>

        <div id="complaint-description-container">
            <legend>Description of Complaint Reason</legend>
            <textarea placeholder="Describe the reason of your complaint in at least 20 characters"
                name="complaint-textarea" id="complaint-description"></textarea>
        </div>

        <fieldset id="solutions-group">
            <legend>Desired Solution</legend>
            <input type="radio" name="solutions" id="refund" value="refund">
            <label for="refund">Refund</label>

            <input type="radio" name="solutions" id="exchange" value="exchange">
            <label for="exchange">Exchange</label>

            <input type="radio" name="solutions" id="other-solution" value="other">
            <label for="other-solution">Other</label>
        </fieldset>

        <div id="solution-description-container">
            <legend>Description of Desired Solution</legend>
            <textarea placeholder="Describe the desired solution to your issue in at least 20 characters"
                name="solution-textarea" id="solution-description"></textarea>
        </div>
        <div id="btn-container">
            <button type="submit" id="submit-btn">Submit</button>
            <span id="message-box" aria-live="polite"></span>
        </div>

    </form>

    <script src="script.js"></script>
</body>

</html>
/* file: styles.css */
* {
    box-sizing: border-box;
}

h1 {
    text-align: center;
}

#form {
    max-width: 70%;
    margin: auto;
    border-radius: 10px;
    box-shadow: rgba(0, 0, 0, 0.35) 0px 5px 15px;
    padding: 10px;
}

input {
    border-color: rgb(118, 118, 118);
}

#personal-info input, #product-info input {
    width: 100%;
    margin-bottom: 10px;
}


fieldset {
    margin-bottom: 10px;
    border-radius: 5px;
    border-color: rgb(118, 118, 118);
}

textarea {
    width: 100%;
    border-color: rgb(118, 118, 118);
}

#btn-container {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

#submit-btn, #clear-btn {
    margin: 10px 15px 0;
}

/* file: script.js */
const fullName = document.getElementById('full-name')
const email = document.getElementById('email')
const orderNo = document.getElementById('order-no')
const productCode = document.getElementById('product-code')
const quantity = document.getElementById('quantity')
const complaintsGroup = document.getElementById('complaints-group')
const otherComplaints = document.getElementById('other-complaint')
const checkboxes = document.querySelectorAll("input[type='checkbox']")
const complaintDescription = document.getElementById('complaint-description')
const solutionsGroup = document.getElementById('solutions-group')
const radio = document.querySelectorAll("input[type='radio']")
const otherSolution = document.querySelectorAll('other-solution')
const solutionDescription = document.getElementById('solution-description')
const form = document.getElementById('form')
const message = document.getElementById('message-box')


const isSomeChecked = (input) => {
  let newArr = []
  for (let i = 0; i < input.length; i++) {
    newArr.push(input[i].checked)
  }
  return newArr
}

const validateForm = () => {
  const name = fullName.value;
  const emailRegex = /(.+)@.+\..+/;
  const orderNoRegex = /2024\d{6}/;
  const productCodeRegex = /[a-z]{2}\d{2}-[a-z]\d{3}-[a-z]{2}\d/i;
  const descriptionRegex = /.{20,}/
  const complaintsGroupArray = isSomeChecked(checkboxes)
  const solutionItemsArray = isSomeChecked(radio)

  return {
    "full-name": name === "" ? false : true,
    "email": emailRegex.test(email.value),
    "order-no": orderNoRegex.test(orderNo.value),
    "product-code": productCodeRegex.test(productCode.value),
    "quantity": quantity.value > 0 ? true : false,
    "complaints-group": complaintsGroupArray.includes(true),
    "complaint-description": otherComplaints.checked ? descriptionRegex.test(complaintDescription.value) : true,
    "solutions-group": solutionItemsArray.includes(true),
    "solution-description": !otherSolution.checked ? descriptionRegex.test(solutionDescription.value) : true

  }
}

const changeBorder = (sth, input) => {
  sth === true ? input.style.borderColor = "green" : input.style.borderColor = "red"
}



fullName.addEventListener("change", () => {
  validateForm()
  changeBorder(validateForm()["full-name"], fullName)
})

email.addEventListener("change", () => {
  validateForm()
  changeBorder(validateForm()["email"], email)
})

orderNo.addEventListener("change", () => {
  validateForm()
  changeBorder(validateForm()["order-no"], orderNo)
})
productCode.addEventListener("change", () => {
  validateForm()
  changeBorder(validateForm()["product-code"], productCode)
})
quantity.addEventListener("change", () => {
  validateForm()
  changeBorder(validateForm()["quantity"], quantity)
})
complaintsGroup.addEventListener("change", () => {
  validateForm()
  changeBorder(validateForm()["complaints-group"], complaintsGroup)
})
solutionsGroup.addEventListener("change", () => {
  validateForm()
  changeBorder(validateForm()["solutions-group"], solutionsGroup)
})

complaintDescription.addEventListener("change", () => {
  validateForm()
  changeBorder(validateForm()["complaint-description"], complaintDescription)
})
solutionDescription.addEventListener("change", () => {
  validateForm()
  changeBorder(validateForm()["solution-description"], solutionDescription)
})

const isValid = (testing) => {
  return (
    testing["full-name"] &&
    testing["email"] &&
    testing["order-no"] &&
    testing["product-code"] &&
    testing["quantity"] &&
    testing["complaints-group"] &&
    testing["complaint-description"] &&
    testing["solutions-group"] &&
    testing["solution-description"]
  );
}


form.addEventListener("submit", (e) => {
  e.preventDefault
  console.log(Object.values(validateForm()))
  console.log(isValid(validateForm()))
  if (isValid(validateForm())) {
    form.submit
    message.textContent = "validation complete"
  } else {
    message.textContent = "try again"

  }

});




Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36

Challenge Information:

Build a Customer Complaint Form - Build a Customer Complaint Form

**Your isValid function should take the validateForm()** as its argument and return true` when all the form fields have been filled correctly

Use console.log to write the inputs the tests are sending to your function and again to see how your function deals with them.

You might have to do this for each individual input.

i changed the return statement on my validateFunction form

  return {
    "full-name": name===""?false:true,
    "email":  emailRegex.test(email.value),
    "order-no": orderNoRegex.test(orderNo.value),
    "product-code": productCodeRegex.test(productCode.value),
    "quantity": quantity.value>0 ? true:false,
    "complaints-group": complaintsGroupArray.includes(true),
    "complaint-description": otherComplaints.checked &&complaintDescription.value.length >= 20,
    "solutions-group": solutionItemsArray.includes(true),
    "solution-description": !otherSolution.checked &&solutionDescription.value.length >= 20

  }

and have wrapped all my input to my isValid function into a console.log

console.log(validateForm()["full-name"])
   console.log(validateForm()["email"])
   console.log(validateForm()["order-no"])
   console.log(validateForm()["product-code"])
   console.log(validateForm()["quantity"])
   console.log(validateForm()["complaints-group"])
   console.log(validateForm()["complaint-description"])
   console.log(validateForm()["solutions-group"])
   console.log(validateForm()["solution-description"])

and the results to the console statements seem to be bringing the correct stuff, what am I missing please, I am really confused

Isn`t that what my function is doing ?

instead of calling the function, you should set the logs in a way that you see what are the values of the form when the function is called, so you see what the tests are using and you can see how your function reacts to those

I still don`t get it, i tried naming the object and then logging the result within the function

const obj =  {
    "full-name": name===""?false:true,
    "email":  emailRegex.test(email.value),
    "order-no": orderNoRegex.test(orderNo.value),
    "product-code": productCodeRegex.test(productCode.value),
    "quantity": quantity.value>0 ? true:false,
    "complaints-group": complaintsGroupArray.includes(true),
    "complaint-description": otherComplaints.checked &&complaintDescription.value.length >= 20,
    "solutions-group": solutionItemsArray.includes(true),
    "solution-description": !otherSolution.checked &&solutionDescription.value.length >= 20
  }
  console.log(obj)
  return obj

the results are the same but the only thing I noticed is that it seems to be returning two objects for each change like this

{ 'full-name': true,
  email: false,
  'order-no': false,
  'product-code': false,
  quantity: false,
  'complaints-group': false,
  'complaint-description': false,
  'solutions-group': false,
  'solution-description': false }
{ 'full-name': true,
  email: false,
  'order-no': false,
  'product-code': false,
  quantity: false,
  'complaints-group': false,
  'complaint-description': false,
  'solutions-group': false,
  'solution-description': false }

Could that be the main issue ?

If you console.log within the function and then console.log calling the function that would be normal, right?

Unfortunately here, you can’t see the values of the inputs, so you don’t know what the tests are doing. You can only see the result, which doesn’t really tell you much.

hey iI was kinda busy with school work am so sorry about the late reply, but i honestly still don’t understand you

Are you able to log the input to the console?

For example if you type in the name or product code, are you able to log that name or product code entered to the console using console.log()?

The automated tests are sending input to your function, but you don’t know what the input is, so you can’t fix it.

ok so i have tried to console the value after I inserted some inputs ,Only my solutionsgroup and complaints group return undefined the rest are fine but my function still works

You are trying to discover what values the tests are sending to your inputs. Do you have a question about that?

form.addEventListener("submit", (e)=>{
    console.log(fullName.value)
    console.log(email.value)
    console.log(orderNo.value)
    console.log(productCode.value)
    console.log(quantity.value)
    console.log(complaintsGroup.value)
    console.log(complaintDescription.value)
    console.log(solutionsGroup.value)
    console.log(solutionDescription.value)
  // e.preventDefault
//  console.log(Object.values(validateForm())) 
  // console.log(isValid(validateForm()))
 if( isValid(validateForm()) ){
  //  form.submit

   message.textContent= "validation complete"
 }else{
   message.textContent= "try again"

 }

This is what i tried doing but am not getting the values when I try running the tests

I’m curious why you put these into the submit event listener. This test does not really mention submit.

  1. Your isValid function should take the validateForm() as its argument and return true when all the form fields have been filled correctly.

Do your form fields evaluate the input only when the form is submitted?

Also, it looks like the console.log messages won’t show in the FCC editor console. You’ll need to open the browser dev tools console (F12 usually) to see them

hmm ok what we ae trying to do is to get the value of our inputs that the tests are sending right ? that means I canhit run test without filling my inputs and the values from the est should be log. but on the browser console its giving undefined

1 Like

Yes, when you click “Run Tests” the tests will set fullName.value etc to something then see how your function reacts. You want to find out what it’s been set to that causes it to fail.

You have the right idea. Check the browser console for the output.

Can you share a screenshot

Here`s a screenshot

Ok, can you think of why it would be undefined? Those are global variables?

EDIT: Are you typing those in at the prompt there?

Where did the console.log lines go from your code?