0

I'm testing this code but the variable "name" result returns undefined.

class Person{

    constructor(name){

        this.name = name;        

    }

    info(){

        alert(`Your name is ${this.name}`);

    }

}

var n = document.getElementById("txtName").value;

var person = new Person(n);

var btn = document.getElementById("btn");
btn.onclick = person.info;

Where's the problem?

eroberti
  • 1
  • 1

0 Answers0