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

160
Views
¿Cuál es la declaración que necesito a continuación para determinar mi salida dado un total?

Soy bastante nuevo en JavaScript, así que disculpas por adelantado, ¡pero también quiero aprender!

En mi formulario html le pido al cliente 3 números (número 1,2,3) y luego en mi JavaScript calculo el total de todos ellos. Necesito resolver mi siguiente bit de código para poder:

  1. Dado el total de los números dados, puedo imprimirle al cliente que su artículo es gratis (menos de 180) o tiene un costo (más de 180)
  2. Dado que el número está por debajo o por encima de cierta cantidad, devuelve un mensaje de error

¿Cuál sería el mejor lugar para ir con esto?

 function Calculate() { var number1 = document.getElementById("number1").value; var number2 = document.getElementById("number2").value; var number3 = document.getElementById("number3").value; // var totalOfNumbers = Number(number1) + Number(number2) + Number(number3); document.getElementById("total").innerHTML = Number(number1) + Number(number2) + Number(number3); }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Necesita usar una construcción if .

El código sería: -

 function Calculate() { var number1 = document.getElementById("number1").value; var number2 = document.getElementById("number2").value; var number3 = document.getElementById("number3").value; // use parseInt instead of Number() var totalOfNumbers = parseInt(number1) + parseInt(number2) + parseInt(number3); // string message to be displayed var message = ""; // enter you own values var minAmount = 0; var maxAmount = 1000; // checking if total of the numbers is under or over a certain amount; // if it is, then showing an error message. if (totalOfNumbers < minAmount || totalOfNumbers > maxAmount) { message = "Error! Please enter valid amounts." } // Checking if total of the numbers is under 180; // if it is, then displaying the item is free. else if (totalOfNumbers < 180) { message = "You're item is free!"; } // Checking if total of the numbers is greater than or equal to 180; // if it is, then displaying the item is not free, and its cost. else { message = "You're item is not free. It has a cost of $" + totalOfNumbers; } document.getElementById("total").innerHTML = message; }
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!