on-internet
← Community

Creating simple calculator

Stack Overflow ·

I am trying to solve a problem given to me and it involves using basic loops, functions and conditions. I have been given the below: // TODO: complete program console.log(calculate(4, "+", 6)); // Must show 10 console.log(calculate(4, "-", 6)); // Must show -2 console.log(calculate(2, "*", 0)); // Must show 0 console.log(calculate(12, "/", 0)); // Must show Infinity and this is my attempt (not working of course). Can anyone give me a nudge of a pointer as to what I am doing wrong? function calculate(n1, n2, n3) { let calc if n2 = "+" { (calc = +) }; else if n2 = "-" { (calc = -) }; else if n2

Comments

Sign in or sign up to comment and upvote.

No comments yet.