JavaScript Calculator calculations issue

I’m building JavaScript Calculator project. A project by freeCodeCamp. But I found an issue.
For example, If you type 3 + 5 * 6 - 2 / 4 on calculator buttons you will see on the console:


So I want to convert this string from "3+5*6-2/4" to "32.5" .
How to do that?

Link to the project link:

Does eval() do what you want?

It is not working. They have written in the console that eval() is a dangerous function!!

As your buttons limit you to having only numbers and arithmetic operators, I don’t think eval() will be dangerous in your code.

On click of the equals button you need to replace all X by * and then call a function such as this:

function evaluate() {
  display.innerText = eval(display.innerText);

Where ‘display’ is your paragraph element.

Where to put evaluate() function?
Could you help me to put it on my code?

eval is insufficient logic, unless you’ve been very careful with User Story 13…

My code above is ordinary JavaScript. I do not know how to do that in your React sandbox.

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