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

161
Views
¿Por qué no se muestra nada? ¿Arruiné mi declaración if?

Así que tengo este script que obtiene 2 precios, y luego encuentra la suma, y luego encuentra un porcentaje de la suma según el estado que elija, y luego agrega el porcentaje. Este script funcionó bastante bien sin la declaración if..else, pero ahora que lo agregué, no funcionará. Por favor ayuda. Guion:

 <!DOCTYPE html> <html> <head> <title>Test!!!!!</title> <style> </style> </head> <body> <h2> Price checker </h2> <input id = "x" type = "number" placeholder = "Price 1" > <br><br><br> <input id = "y" type = "number" placeholder = "Price 2" > <br><br><br> <select id="s"> <option value="NJ">NJ</option> <option value="NY">NY</option> <option value="PA">PA</option> <option value="FL">FL</option> </select> <br><br><br> <button onclick = "theFunction()">Calculate price</button> <p id = "d"></p> <script> function theFunction() { var x = document.getElementById("x").value var y = document.getElementById("y").value var z = +x + +y var v = document.getElementById("s").value var percentToGet; var percent; var final; if v == "NJ" { var percentToGet = 6.625; var percent = (percentToGet / 100) * z; var final = +percent + +z } else if v == "NY" { var percentToGet = 4; var percent = (percentToGet / 100) * z; var final = +percent + +z }else if v == "PA" { var percentToGet = 2; var percent = (percentToGet / 100) * z; var final = +percent + +z } else if v == "FL" { var percentToGet = 6; var percent = (percentToGet / 100) * z; var final = +percent + +z } document.getElementById("d").innerHTML = z + " " + final } </script> </body> </html>

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Su declaración if en la etiqueta del script es un código javascript que no tiene paréntesis.
Será => if (v == "NJ") { }

Consulte estos documentos web de MDN para obtener más información si... si no

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!