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

259
Views
No puedo mostrar el resultado de una calculadora en javascript, el resto del código no funciona

Hola, estoy tratando de crear una calculadora pero no puedo mostrar el resultado. Primero traté de almacenar el retorno en una variable, luego almacené mi función en una variable. Hice una alerta (), luego hice una alerta con tubería para mis diferentes funciones después de mi condición de cambio, pero nada funciona.

Aquí está el código que hice. ¿Puedes decirme cómo mostrar el resultado?

 let choice = prompt('What operation would you like to do?\n \n 1: Addition\n 2:Soustraction\n 3: Multiplication\n 4: Division'); let firstNumber = parseInt(prompt('write your first number')); let secondNumber = parseInt(prompt('write your second number')); let result; do { isNaN() } while (firstNumber, secondNumber); result = function addition() { return firstNumber + secondNumber; } result = function multiplication() { return firstNumber * secondNumber; } result = function soustraction() { return firstNumber - secondNumber; } result = function division() { return firstNumber / secondNumber; } switch (choice) { case "1": addition(); break; case "2": multiplication(); break; case "3": soustraction(); break; case "4": division(); break; default: 'This number isn\'t in the list' } alert(result(firstNumber, secondNumber)); try { switch (division) { case secondNumber = 0: alert('You can\'t split by 0'); } } catch { console.error(error.stack); }

about 4 years ago · Santiago Gelvez
1 answers
Answer question

0

Reescribí las cosas un poco para que funcionara. Aquí estaba mi enfoque de lo que estabas intentando:

 let choice = prompt('What operation would you like to do?\n \n 1: Addition\n 2:Soustraction\n 3: Multiplication\n 4: Division'); function checkFirstNumber(anotherTry = null) { let bad = true; let firstIn; if (anotherTry == null) { firstIn = prompt('write your first number') } else { firstIn = prompt('You did not enter a valid number. Please write your first number.') } bad = isNaN(firstIn); if (bad != false) { checkFirstNumber(true); } else { return parseFloat(firstIn); } } function checkSecondNumber(anotherTry = null) { let bad = true; let firstIn; if (anotherTry == null) { firstIn = prompt('write your second number') } else { firstIn = prompt('You did not enter a valid number. Please write your second number.') } bad = isNaN(firstIn); if (bad != false) { checkFirstNumber(true); } else { return parseFloat(firstIn); } } let firstNumber = checkFirstNumber(); let secondNumber = checkSecondNumber(); let result; // do { // isNaN() // } while (firstNumber, secondNumber); function addition(inFirst, inSecond) { return inFirst + inSecond; } function multiplication(inFirst, inSecond) { return inFirst * inSecond; } function soustraction(inFirst, inSecond) { return inFirst - inSecond; } function division(inFirst, inSecond) { return inFirst / inSecond; } switch (choice) { case "1": result = addition(firstNumber, secondNumber); break; case "2": result = multiplication(firstNumber, secondNumber); break; case "3": result = soustraction(firstNumber, secondNumber); break; case "4": if (secondNumber == 0) { result = 'You can\'t divide by 0. Please try again.'; } else { result = division(firstNumber, secondNumber); } break; default: 'This number isn\'t in the list' } alert(result); location.reload();

about 4 years ago · Santiago Gelvez 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!