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

234
Views
Javascript Basic calculator with parameters--not getting output

below is my problem solving question.

Basic calculator with parameters In this lab, we will practice for loop with an array and functions and conditionals. Your task for this lab is to:

Create a function named performMath that accepts three parameters - number1, number2 and operation If operation is '+', add the numbers and return the result If operation is '*', multiply the numbers and return the result

My code for aforementioned question,but am not getting correct result, please check and confirm do i code correctly?

let number1 =20
let number2 =10
function performMath(number1,number2){
return number1 + number2
}
console.log(performMath(number1 + number2));
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

You must use three arguments as your assignment says:

let number1 =20
let number2 =10
let operation = '+'

function performMath(num1,num2,oper){
  if(oper === '-')
    return num1 - num2
  else if(oper === '+')
    return num1 + num2
  else if(oper === '*')
    return num1 * num2
}

console.log(performMath(number1, number2, '-'));
console.log(performMath(number1, number2, '+'));
console.log(performMath(number1, number2, '*'));
about 4 years ago · Juan Pablo Isaza Report

0

function performMath(num1, num2, calc){
    if (calc === '+') return num1 + num2;
    if (calc === '-') return num1 - num2;
    if (calc === '*') return num1 * num2;
    if (calc === '/') return num1 / num2;
    return "something went wrong";
}
console.log(performMath(12, 10, "+"));
console.log(performMath(4, 3, "*"));
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!