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

248
Views
anidar if./else if declaración por defecto a last else incluso si los parámetros anteriores son verdaderos
Pizza.prototype.getPrice = function() { const price = 10 if (this.pizzaSize === "medium") { if (this.toppings === "cheese") { console.log(price + 6); } else if (this.toppings === ("cheese", "pepperoni")) { console.log(price + 7); } else { console.log(price + 8); } } else if (this.pizzaSize === "large") { if (this.toppings === "cheese") { console.log(price + 11); } else if (this.toppings === ("cheese", "pepperoni")) { console.log(price + 12); } else { console.log(price + 13); } } else if (this.pizzaSize === "xlarge") { if (this.toppings === "cheese") { console.log(price + 15); } else if (this.toppings === ("cheese", "pepperoni")) { console.log(price + 16); } else { console.log(price + 17); } } } function Pizza(pizzaSize, toppings) { this.pizzaSize = pizzaSize; this.toppings = toppings; } //UI Logic --- function displayPizzaInfo(pizzaToDisplay) { let pizzaInfo = $("p#output"); let htmlForPizzaInfo = pizzaToDisplay.pizzaSize + " " + pizzaToDisplay.toppings + " Pizza" + " " + "$ " + pizzaToDisplay.getPrice(); pizzaInfo.html(htmlForPizzaInfo); } $(document).ready(function(){ $("form#pizzaOrder").submit(function(event) { event.preventDefault(); const pizzaSize = $("#pizzaSize").val(); let ele = []; $("input:checkbox[name=topping]:checked").each(function() { ele.push($(this).val()); }) let myPizza = new Pizza(pizzaSize, ele) displayPizzaInfo(myPizza); // let myPizzaPrice = myPizza.getPrice(); }); }); let myPizza = new Pizza("medium", "cheese"); myPizza.getPrice(); Expected Output: 16

La prueba anterior ya no se aplica y el resultado esperado se convierte en 18. Creo que la forma en que escribo mis if anidados o los if están estructurados incorrectamente. Hice TDD y mientras escribía mis pruebas, todas funcionaron sin darme cuenta de que mis pruebas anteriores ya no funcionaban. Estoy buscando que mi prototipo.getPrice coincida con mis declaraciones if y, por lo tanto, se corresponda correctamente con lo que el usuario ve en la aplicación web. Cualquier ayuda sería muy apreciada. ¡Gracias!

about 4 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 Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!