JSFiddle - React, Tailwind, and code Playground
HTML
<body>
<h1>Students</h1>
<div id="output">
</div>
<script src="students.js"></script>
</body>
JavaScript
function print(message) {
var outputDiv = document.getElementById('output');
outputDiv.innerHTML = message;
}
var message = '';
var search;
var students = [
{Name: 'John', Track: 'ios' , Achievements: 23, Points: 123 },
{Name: 'Susan', Track: 'Web Design', Achievements: 12, Points: 333},
{Name: 'Nazir', Track: 'Ruby', Achievements: 3, Points: 233},
{Name: 'Rui', Track: 'Business', Achievements: 123, Points: 3435},
{Name: 'Joao', Track: 'Perl', Achievements: 78, Points: 667}
];
function findStudent(student) {
var report ='<h2>Student Found!</h2>';
report += '<p>Name: ' + student.Name + '</p>';
report += '<p>Track: ' + student.Track + '</p>';
report += '<p>Achievements: ' + student.Achievements + '</p>';
report += '<p>Points: ' + student.Points + '</p><br><br>';
return report;
}
while (true){
search = prompt('Please enter the name...');
if (search.toLowerCase() === "quit"){
break;
}
for(var i = 0; i < students.length; i += 1){
var student = students[i];
if(student.Name === search){
message = findStudent(student);
print(message);
}
}
}