Solution 1 :

let inpNom = document.getElementById('nombre');
let inpApe = document.getElementById('apellido');
let inpEdad = document.getElementById('edad');
let inpHobb = document.getElementById('Hobbies');
let btnSend = document.getElementById('send');
let btnReset = document.getElementById('reset');
let result = document.getElementById('text');

class Persona {
  constructor() {
    this.nombre = inpNom.value;
    this.inpApe = inpApe.value;
    this.inpEdad = inpEdad.value;
    this.inpHobb = inpHobb.value;
  }
}

function createPerson() {
  let newPersona = new Persona
  result.textContent = `Hola mi nombre es ${newPersona.nombre} ${newPersona.inpApe} mi edad es ${newPersona.inpEdad} y me gusta mucho hacer ${newPersona.inpHobb}.`;
}

inputs = document.getElementsByTagName("input");
for (var i = 0; i < inputs.length; i++) {
  inputs[i].addEventListener("input", createPerson)
}

function clearInputs() {
  for (var i = 0; i < inputs.length; i++) {
    inputs[i].value = ""
  }
  inputs[0].dispatchEvent(new Event("input"))
}
* {
  margin: 0;
  padding: 0;
  outline: 0;
  box-sizing: border-box;
  font-family: fantasy
}

body {
  background-image: linear-gradient(#cc3290, #c41010);
  width: 100%;
  height: 100vh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}

.distribucion {
  display: flex;
  flex-direction: column;
  justify-content: space-around;
  align-items: center;
}

.form {
  width: 250px;
  height: 250px;
  box-shadow: 0px 1px 50px #2a2a2a;
  border: 1px solid #fff;
  border-radius: 15px;
  color: #fff;
  font-size: 17px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  justify-content: space-evenly;
}

.result {
  width: 40%;
  height: 15%;
  border: 2px solid #fff;
  border-radius: 10px;
  color: #fff;
  padding: 10px;
}

.btns {
  width: 90px;
  height: 100px;
  display: flex;
  flex-direction: column;
  justify-content: space-evenly;
  border-left: 15px;
}

button {
  cursor: pointer;
  border-bottom: 10px;
  border-radius: 15px;
  padding: 5px 20px;
  letter-spacing: 2px;
  background-color: transparent;
}

#send {
  border: 2px solid #fff;
  color: #050505;
}

#reset {
  border: 2px solid rgb(15, 15, 15);
  color: #ffffff;
}
<div class="distribucion">
  <form class="form">
    <label for="nombre">Name:</label>
    <input type="text" id="nombre">
    <br>
    <label for="apellido">Apellido:</label>
    <input type="text" id="apellido">
    <br>
    <label for="edad">Edad: </label>
    <input type="text" id="edad">
    <br>
    <label for="hobbies">Hobbies:</label>
    <input type="text" id="Hobbies">
  </form>
  <div class="btns">
    <button id="reset" onclick="clearInputs()">Reset</button>
  </div>
</div>
Output:
<div id="text">Hola mi nombre es mi edad es y me gusta mucho hacer .</div>

Solution 2 :

that ?
FormData can directly create your object

const myForm = document.forms['my-form']
  ,   ArrObj = []
  ;
myForm.onsubmit = e => 
  {
  e.preventDefault()

  ArrObj.push( Object.fromEntries(new FormData(myForm).entries()) )

  console.clear()
  console.log( ArrObj ) 
  }
* {
  margin          : 0;
  padding         : 0;
  outline         : 0;
  box-sizing      : border-box;
  font-family     : fantasy
  }
body {
  background-image: linear-gradient(#cc3290, #c41010);
  width           : 100%;
  height          : 100vh;
  display         : flex;
  justify-content : center;
  align-items     : center;
  }
.distribucion {
  display         : flex;
  flex-direction  : column;
  justify-content : space-around;
  align-items     : center;
  }
fieldset {
  width           : 250px;
  height          : 250px;
  box-shadow      : 0px 1px 50px #2a2a2a;
  border          : 1px solid #fff;
  border-radius   : 15px;
  color           : #fff;
  font-size       : 17px;
  padding         : 10px;
  display         : flex;
  flex-direction  : column;
  justify-content : space-evenly;
  }
.result {
  width           : 40%;
  height          : 15%;
  border          : 2px solid #fff;
  border-radius   : 10px;
  color           : #fff;
  padding         : 10px;
  }
.btns {
  width           : 90px;
  height          : 100px;
  display         : flex;
  flex-direction  : column;
  justify-content : space-evenly;
  border-left     : 15px;
  }
button {
  cursor          : pointer;
  border-bottom   : 10px;
  border-radius   : 15px;
  padding         : 5px 20px;
  letter-spacing  : 2px;
  background-color: transparent;
  }
button[type=submit] {
  border          : 2px solid #fff;  
  color           : #050505;
  }
button[type=reset] {
  border          : 2px solid rgb(15, 15, 15);
  color           : #ffffff;
  }

.as-console-wrapper { max-height:100% !important; top:0; left:50% !important; width:50%; }
.as-console-row         { background-color: yellow; }
.as-console-row::after  { display:none !important; }
<form name="my-form" class="distribucion">
  <fieldset>
    <label> Name:     </label> <input type="text" name="nombre"   ><br>
    <label> Apellido: </label> <input type="text" name="apellido" ><br>
    <label> Edad:     </label> <input type="text" name="edad"     ><br>
    <label> Hobbies:  </label> <input type="text" name="Hobbies"  >
  </fieldset>
  <div class="btns">
    <button type="submit"> Send  </button>
    <button type="reset" > Reset </button>
  </div>
</form>

if you want a specific access method just add :

ArrObj.get = i =>
  {
  if (i<ArrObj.length)
    {
    let el = ArrObj[i]
    return `Hola mi nombre es ${el.nombre} ${el.inpApe} mi edad es ${el.inpEdad} y me gusta mucho hacer ${el.inpHobb}.`
    }
  else return 'out of range'
  }

Problem :

I want to generate objects automatically when the data is entered in the inputs.

I have already made a construction function, my doubt is how I make the data received by the constructor to be the data entered in the inputs

**my objective is that the name, surname, age and hobby are printed on the screen **

<div class="distribucion">
  <form class="form">
    <label for="nombre">Name:</label>
    <input type="text" id="nombre">
    <br>
    <label for="apellido">Apellido:</label>
    <input type="text" id="apellido">
    <br>
    <label for="edad">Edad: </label>
    <input type="text" id="edad">
    <br>
    <label for="hobbies">Hobbies:</label>
    <input type="text" id="Hobbies">
  </form>
  <div class="btns">
    <button id="send">Send</button>
    <button id="reset">Reset</button>
  </div>
</div>
* {
  margin          : 0;
  padding         : 0;
  outline         : 0;
  box-sizing      : border-box;
  font-family     : fantasy
  }
body {
  background-image: linear-gradient(#cc3290, #c41010);
  width           : 100%;
  height          : 100vh;
  display         : flex;
  justify-content : center;
  align-items     : center;
  }
.distribucion {
  display         : flex;
  flex-direction  : column;
  justify-content : space-around;
  align-items     : center;
  }
.form {
  width           : 250px;
  height          : 250px;
  box-shadow      : 0px 1px 50px #2a2a2a;
  border          : 1px solid #fff;
  border-radius   : 15px;
  color           : #fff;
  font-size       : 17px;
  padding         : 10px;
  display         : flex;
  flex-direction  : column;
  justify-content :space-evenly;
  }
.result {
  width           : 40%;
  height          : 15%;
  border          : 2px solid #fff;
  border-radius   : 10px;
  color           : #fff;
  padding         : 10px;
  }
.btns {
  width           : 90px;
  height          : 100px;
  display         : flex;
  flex-direction  : column;
  justify-content : space-evenly;
  border-left     : 15px;
  }
button {
  cursor          : pointer;
  border-bottom   : 10px;
  border-radius   : 15px;
  padding         : 5px 20px;
  letter-spacing  : 2px;
  background-color: transparent;
  }
#send {
  border          : 2px solid #fff;  
  color           : #050505;
  }
#reset {
  border          : 2px solid rgb(15, 15, 15);
  color           : #ffffff;
  }
let inpNom   = document.getElementById('nombre');
let inpApe   = document.getElementById('apellido');
let inpEdad  = Number(document.getElementById('edad'));
let inpHobb  = document.getElementById('Hobbies');
let btnSend  = document.getElementById('send');
let btnReset = document.getElementById('reset');
let result   = document.getElementById('text');

class Persona {
  constructor() {
      this.nombre   = inpNom.nodeValue;
      this.apellido = apellido;
      this.edad     = edad;
      this.hobbie   = hobbie;
  }
  copiar() {
    result.textContent = `Hola mi nombre es ${this.nombre} ${this.inpApe} mi edad es ${this.inpEdad}
    y me gusta mucho hacer ${this.inpHobb}.`;
  }
}

function createPerson() {
  let create = Persona.prototype.copiar();
}

btnSend.addEventListener('click',createPerson);

Comments

Comment posted by Germán Faller

Why this title is in Spanish?

Comment posted by brian diaz

ups, I already fixed it:)

Comment posted by Germán Faller

do you really need to use a Class?

Comment posted by Endothermic_Dragon

Try selecting all of the inputs using querySelectorAll, looping through them to add an event listener that listens for ‘input’ (

Comment posted by brian diaz

I think so, I want to create several objects

Comment posted by Endothermic_Dragon

Try viewing it full page – the snippet looks weird when it’s small (though it technically still works).

By