skip to Main Content

the problem is i want the result like this

enter image description here

but it does not show it

what i want is to make a program that show names on webpage as i add them through the input box using array

it’s a very easy program but i don’t whay do i get this error

This is the code :

var students = [];

document
  .getElementById("add-student-btn")
  .addEventListener("click", function() {
    var SNNA1me = document.getElementById("student-input").value;
    student.push(SNNA1me);
    document.getElementById("students").innerHTML = students;
  });
<div style="text-align: center; margin-top: 100px">
  <input type="text" id="student-input" />
  <button id="add-student-btn">Submit</button>
  <div id="students" style="font-size: 30px"></div>
</div>

2

Answers


  1. student.push(SNNA1me) should be students.push(SNNA1me)

    Login or Signup to reply.
  2. Because your student is undefined
    Correction should be

        var students = [];
           document.getElementById("add-student-btn").addEventListener("click", function() {
        var SNNA1me = document.getElementById("student-input").value;
        students.push(SNNA1me);
        document.getElementById("students").innerHTML = students;
      });
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search