codedamn

Basic calculator with parameters

Created by Codedamn about a year ago

0

No description provided

7 Comments

    0
    0

    ezz

    @0xirvan

    Irvan Pramana Putra

    @0xirvan

    0

    function performMath(number1 , number2 , operation) { if(operation == '+'){ return number1 + number2 }else if(operation == ''){ return number1 * number2 } } x = performMath(5 , 4 , '') console.log(x)

    @navis

    NAVNEETHRAM VK

    @navis

    0

    // write your code below const operation='+' function performMath(number1,number2 ){ if(operation == '+'){ return number1+number2 } else if(operation ==''){ return number1number2 } } console.log(performMath(2,4))

    @anamuddinahmad

    Anamuddin Ahmad

    @anamuddinahmad

    0

    This type of exercises are not beginner friendly. Before this, you might have taught us comparison operators. Without them, how one should know how to compare the value of operation?

    @isufiyanmalik

    Sufiyan Malik

    @isufiyanmalik

    0

    // write your code below const arr = [ { num1: 10, num2: 20, operation: '+' }, { num1: 280, num2: 229, operation: '-' }, { num1: 101, num2: 202, operation: '*' }, { num1: 28, num2: 20.1, operation: '%' }, { num1: 28, num2: 20.1, operation: 'hello' } ]

    const performMath = (number1, number2, operation) => { const result = { '+': number1 + number2, '-': number1 - number2, '*': number1 * number2, '%': number1 % number2 }

    return result[operation] ?? 'Operator is invalid!'
    

    }

    arr.forEach(element => { const finalResult = performMath(element.num1, element.num2, element.operation) console.log(finalResult) })

    @mihir03

    Mihir Dalal

    @mihir03

    0

    Question:- when i am solveing this question i found for else condition if i keep square bracket giveing me error what is the reason ? code:- function performMath(number1,number2,operation){ if (operation == '+'){ return number1+number2 }else (operation == '') return number1number2 } console.log(performMath(5,5,'+')) console.log(performMath(5,4,'*'))

    @cannyharshith

    HARSHITH GRANDHI

    @cannyharshith

Your comment