Created
April 1, 2015 17:26
-
-
Save miragedeb/8bc36cd9c761d011b474 to your computer and use it in GitHub Desktop.
Printing Students
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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