V
V
vljs2018-01-30 18:07:38
JavaScript
vljs, 2018-01-30 18:07:38

How to parseInt '+'?

Hi all. Does anyone have any idea how to make a number out of a string ("+" ==> +)?
Is my state in React returning Math.random() > 0.5 ? ` + ` : ` - `.
Unfortunately, the operation does not take place (outputs 8 "-" 5, for example, but I would like 3).
What I tried to do:

  • parseInt - 8 " - " 5,
  • without quotes - gives a syntax error,
  • with ` (ES6) - same result,
  • Number - error (if Number('+') => NaN),
  • I put both ( ) and { } in state - not that

Good evening everyone!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
C
Codebaker, 2018-01-30
@vljs

k = Math.random() > 0.5 ? eleven;
and replace your sum with A + k * B

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question