Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

179
Views
Función de nomenclatura en JavaScript

Como puede ver en mi código a continuación, cuando nombro mi función discount() , la función no se ejecuta cuando se llama. Sin embargo, si lo nombro discounts() , funciona correctamente. ¿Hay alguna explicación para esto?

 <html lang="en"> <head> <meta charset="UTF-8"> <title>q3</title> </head> <body> <form action=""> <label> Enter Price:</label> <input type="text" name="price" id="name"> <label>(RM)</label><br><br> <label>Enter Discount:</label> <input type="text" name="discount" id="discount"> <label>(%)</label><br><br> <button onclick="discount()">Get Discount total</button><br><br> <input type="text" name="discountPrice" id="discountPrice"> <label>(RM)</label> </form> <script> function discount() { var price = document.getElementById("name").value; var discount = document.getElementById("discount").value; var discountPrice = parseFloat(price) * (1 - parseFloat(discount) / 100); document.getElementById("discountPrice").value = discountPrice; } </script> </body> </html>
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Su código da el siguiente error:

 TypeError: discount is not a function at HTMLButtonElement.onclick (/:14:34)

La razón de esto es que tienes la siguiente línea:

 <input type="text" name="discount" id="discount">

Entonces, cuando usa onclick=discount() , el nombre discount aquí se refiere al elemento <input> , no a la función discount() . Debe usar dos nombres distintos para estos para solucionar el problema.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!