I am trying to make an input box that asks for a student name, and when someone types a certain name, html will print to the screen displaying that certain student's statistics. I am have trouble with this especially since the console doesn't say there are any errors.
Here is my code that does absolutely nothing as of now.
Also, I don't want any prompts, alerts, or anything like that, I want it to purely be on the page.
Basically, I want it to be a search box for a student's name, and then outputs their stats. So when you click the button, and the student's name you entered matches one in the code, the html will display that student's stats.
________________
|STUDENT_NAME_| <=== student name search here. BUTTON
Then output these stats:
track: 'Front End Development',
achievements: '158',
points: '14730'
<DOCTYPE! html>
<html>
<head>
<title>Hello World</title>
</head>
<body>
First name: <input id="first_name">
<button onclick="getStudentReport" id="output"></button>
<hr>
<div id="result"></div>
<script>
var students = [
{
name: 'Hanna',
track: 'Front End Development',
achievements: '158',
points: '14730'
},
{
name: 'Joshua',
track: 'iOS Development with Swift',
achievements: '175',
points: '16375'
},
{
name: 'Becky',
track: 'PHP Development',
achievements: '55',
points: '2025'
},
{
name: 'Jacob',
track: 'Learn WordPress',
achievements: '40',
points: '1950'
},
{
name: 'Dug',
track: 'Rails Development',
achievements: '5',
points: '350'
}
];
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;
}
function say_hi() {
var student = document.getElementById('first_name').value;
if (student.name === students) {
message = getStudentReport(student);
print(message);
}
document.getElementById('result').innerHTML = html;
}
document.getElementById('output').addEventListener('click',
getStudentReport);
</script>
</body>
</html>