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 trialZaid Anki
Full Stack JavaScript Techdegree Graduate 14,514 PointsCompleting the Challenges + adding a "list" command as well! unit 1 Array Course!
This is how i did it!, i did not use anything outside of the video except for 1 new variable (and a couple of copy pastes) for the list command!
var message = '';
var student;
var search;
var stunm = [];
function print(message) {
var outputDiv = document.getElementById('output');
outputDiv.innerHTML = message;
}
function getStudentReport (student){
var report = '<h2>Student: ' + student.name + '</h2>';
report += '<p>Track: ' + student.track + '</p>';
report += '<p>Points: ' + student.points + '</p>';
report += '<p>Achievements: ' + student.achievements + '</p>';
return report
}
for (var i = 0; i < students.length; i += 1) {
student = students[i];
stunm.push(student.name);
}
while (true) {
search = prompt('search student records: type a name [Jody] (type "quit" to end or "list" to see a list of students )');
if (search === null || search.toLowerCase() === 'quit') {
break;
}
for (var i = 0; i < students.length; i += 1) {
student = students[i];
if (student.name === search) {
message += getStudentReport( student );
print(message);
}
}
if (search.toLowerCase() === 'list') {
alert(stunm.join(', '))
}else if (stunm.indexOf(search) < 0){
alert('there is no student with that name');
}
}
1 Answer
Mino Karadzhov
8,167 PointsHello, Zaid ! I think this is a great solution ! Are you experiencing any problems with your code, due to which you are reaching the community ? :)
Zaid Anki
Full Stack JavaScript Techdegree Graduate 14,514 PointsZaid Anki
Full Stack JavaScript Techdegree Graduate 14,514 Pointsother than wondering if i could have written it in a better way (and the video telling us to share our solution) not really! =)