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 trialPiyush Chawla
Courses Plus Student 30 PointsPlease tell me what is wrong in this code?
var arr=[{name:"Piyush",age:24},{name:"Ram",age:26},{name:"Shyam",age:28},{name:"Mohit",age:30},{name:"Rohit",age:32}]
var x;
var a;
function search(s){
for(i=0; i<arr.length; i++){
if(arr[i].name===s){
for(var j in arr[i]){
print(j+":"+arr[i][j]);
}
return;
}
print("name not found");
}
function print(m){
x="<p>"+m+"</p>";
document.write(x);
}
while(true){
a=prompt("enter a name");
if(a==="quit"){
break;
}
search(a);
}
2 Answers
Ginger Cullen
4,301 PointsYour first if statement is missing its closing curly brace.
Jesus Mendoza
23,289 PointsHey Piyush what are you expecting from that code?
Piyush Chawla
Courses Plus Student 30 PointsPiyush Chawla
Courses Plus Student 30 PointsThanks that worked.