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 trialSiddharth Nasare
15,636 PointsMy code for the Student Record Search Challenge Solution
/* JavaScript objects challenge. In this, we are making one data structure about different students and their information. We just need to access that information and print it to the web page as a requirement of the user. Below code is the solution to the challenge. */
function print(message){ document.write(message); }
/* This code is for making first letter capital. I am not using this function in my solution. This is just for a reference.
function capitalize(string) { return string.charAt(0).toUpperCase() + string.slice(1).toLowerCase(); }
*/
/* Data structure. information about all students.*/
var students = [ { name : "Siddharth" , track : "Front End Developer", achievements : 160, points: 4000 }, { name : "Radhika" , track : "CA", achievements : 170, points: 5000 }, { name : "Palak" , track : "Software developer", achievements : 260, points: 40000 }, { name : "Vishwa" , track : "JAVA Developer", achievements : 360, points: 30000 }, { name : "Jay" , track : "Mechanical Engineer", achievements : 132, points: 1000 } ]; var ask; var info = {}; var found = false;
/* Ask the question and then use a loop to go through all the elements of the array. Check whether the requirement is able to fulfil or ask the question again.*/
function call(){ ask = prompt("Search student records: Type a name[Siddharth](or type 'quit' to end)"); } while (true){ call(); if( ask === null || ask.toUpperCase() === "QUIT"){ break; } for (var i = 0; i < students.length; i++){
var p = students[i].name;
if( p.toUpperCase() === ask.toUpperCase() ){
info.Student = students[i].name;
info.Track = students[i].track;
info.Points = students[i].points;
info.Achievements = students[i].achievements;
output();
found = true;
}
} if (!found){ print("<h1> Sorry, " + ask.toUpperCase() + " not found.</h1>") break; } found = false; } /Using function to print on the web page./
function output(){ var HTML = "<h2> Student: " + info.Student + "</h2>"; HTML += "<p> Track: " + info.Track + "</p>"; HTML += "<p> Points: " + info.Points + "</p>"; HTML += "<p> Achievements: " + info.Achievements + "</p>";
print(HTML);
}