Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript Build an Interactive Website Form Validation and Manipulation jQuery Utility Methods

Corey Lyons
Corey Lyons
24,684 Points

Using the 'inArray' method check if the array contains the string 'Andrew'

I can't figure this out help!

app.js
var values = $(".required").map(function() { 
  return $(this).val();
});
$.inArray(true, "Andrew") != -1;
index.html
<!DOCTYPE html>
<html>
<head>
    <title>Modifying Attributes</title>
    <style type="text/css">
        .valid {
            color: green;
            border: 2px solid green;
        }
        .error {
            color: red;
            border: 2px solid red;
        }
    </style>
</head>
<body>

    <p>
        <input type="text" class="required" id="name" value="Andrew">
    </p>

    <p>
        <input type="text" class="required" id="company" value="Treehouse Island, Inc">
    </p>

    <p>
        <input type="text" class="" id="phone" value="555-123-4567">
    </p>

<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="app.js"></script>
</body>
</html>

1 Answer

Hugo Paz
Hugo Paz
15,622 Points

Hi Corey,

You need to check if the string 'Andrew' exists in the 'values' object.

var values = $(".required").map(function() { 
  return $(this).val();
});
$.inArray("Andrew", values);