How to create a system that solves subtraction, multiplication, division, and addition using JavaScript?

Good evening! I’m a beginner and I’m learning how to code a program that solves subtraction, multiplication, division, and addition.
Here’s what I have for multiplication.

I have no idea how to create the other operations! :slight_smile: Is there anyway to create the programs?

Hi @KookieYolo,

Edit your post, select your code and hit the </> button to format code blocks.

var jsRules = "yep";
console.log(jsRules);
2 Likes

Well, I already created a screenshot… I’ll keep what you said in mind!

I can see the screenshot now :slight_smile:

You might want to add a select for operators:

<select id="operator">
  <option value="-">Subtract</option>
  <option value="+">Add</option>
  <option value="*">Multiply</option>
  <option value="/">Divide</option>
</select>

Using eval is considered bad practice but in this case it might help you with your demo.

function calculate() {
  var operator = document.getElementById('operator').value;
  var value = eval(x.value + operator + y.value);
  d.innerHTML = value;
}
1 Like

Ah… Ok. I included the operators and they’re going completely haywire, so where do I put the eva1’s and the operators?

I’ve edited the post to clear that up.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.