• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

134
Views
Cómo imprimir la clase de JavaScript en la tabla

Tengo una clase llamada 'Coche'. Lo que quiero es que cuando el usuario seleccione 'Maruti' de la opción de selección, todos los datos del automóvil rápido se impriman en la tabla. Cuando elijo Maruti, no imprime nada y tampoco hay un error de consola.

 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> </head> <body> <select id="sel" onchange="selected();"> <option>---choose--</option> <option>Maruti</option> <option>Tata</option> </select> <table></table> <script> let Car= class { constructor(name,power,torque,weight){ this.name=name; this.power=power; this.torque=torque; this.weight=weight; } } class Maruti extends Car{ constructor(name,power,torque,weight){ super(name,power,torque,weight); } } class Tata extends Car{ constructor(name,power,torque,weight){ super(name,power,torque,weight); } } var swift = new Maruti('swift',103,100,870); var safari = new Tata('safari',105,138,1070); function selected(){ var sel = document.getElementById('sel').value; for(const key in Car){ if(sel[1]=='Maruti'){ document.querySelector('table').innerHTML+= '<tr>' + '<td>' + key +'</td>'+ '<td>'+ swift[key]+'</td>' + '</tr>'; }else{ document.querySelector('table').innerHTML+= '<tr>' + '<td>' + key +'</td>'+ '<td>'+ safari[key]+'</td>' + '</tr>'; } } } </script> </body> </html>
about 3 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error