Skip to content

Instantly share code, notes, and snippets.

@miragedeb
Created April 1, 2015 17:26
Show Gist options
  • Save miragedeb/8bc36cd9c761d011b474 to your computer and use it in GitHub Desktop.
Save miragedeb/8bc36cd9c761d011b474 to your computer and use it in GitHub Desktop.
Printing Students
var message = '';
var ctr = 0;
var storeSearch = [];
var result = '';
function print(message) {
var outputDiv = document.getElementById('output');
outputDiv.innerHTML = message;
}
function printArray(storeSearch) {
for(var i=0; i<storeSearch.length; i++) {
var student = storeSearch[i];
result += '<h2>Student: ' + student.name + '</h2>';
for(var prop in student) {
result += '<p>' + prop + ': ' + student[prop] + '</p>';
}
}
return result;
}
while(true) {
var searchStr = prompt('Which student do you want to search?');
if(searchStr === null || searchStr.toLowerCase() === 'quit') {
break;
}
for(var i=0; i<students.length; i++) {
var student = students[i];
if(student.name === searchStr) {
storeSearch.push(student);
}
}
}
console.log(storeSearch);
if(storeSearch.length !==0) {
var message = printArray(storeSearch);
print(message);
} else {
print('Sorry but we could not find the student you were looking for.');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment