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 trialMary Chadwick
10,683 PointsHaving major problems finishing this modual with Form Validation and Manipulation. Task 2.
I'm really frustrated. I solved Task 2 before, and then got stuck on Task 3. I've moved on to other modes but it would be nice if I could finish this one. I've had the prerequisites, but the tasks are too difficult and don't seem to relate much to the exercises in the video that I have done and followed through.
function isValidEmail(email){
return email.indexOf("@") != -1;
}
function requiredValues(){
var values = new Array();
return values.input(".required");
}
<!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>
3 Answers
Preston Skaggs
11,818 PointsIs the "isValidEmail(email)" function supposed to return a boolean value? If so I think it should look like this:
function isValidEmail(email){
return email.indexOf("@") !== -1;
}
look here for a reference: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/indexOf
Mary Chadwick
10,683 PointsActually, That is from Task 1 and it passed. It is the second task that is failing. Task 2 is "Create a method called 'requiredValues' that returns an array of all the values of inputs with the class of 'required'."
Preston Skaggs
11,818 PointsThe question is asking you to create a function that returns an array of all input values where the class of the input element is defined as "required". So you need to create an array and add to it every HTML input element that has the class "required". You could do this by running through all the input fields and checking the class by using document.getElementsByTagName().className .
Preston Skaggs
11,818 PointsHere is something to get you started
function requiredValues(){
var req = new Array();
var elements = document.getElementsByTagName("input");
//iterate through your "input" elements here and where elements.className matches add elements.value to the req array
}
return req;
}