Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You will need to use regular expressions, if you do not know what they are you should look them up as it would take too long to explain them in this response. Here is a useful website for regular expressions in JavaScript <a href="https://developer.mozilla.org/en/JavaScript/Guide/Regular_Expressions" rel="nofollow">https://developer.mozilla.org/en/JavaScript/Guide/Regular_Expressions</a>.</p> <p>Assuming that you know regular expressions you should first search for numbers and store all the numbers that you find, if no numbers are found print out an error message. As an added note, you may what to consider searching for mathematical constants such as pi or e. This should work</p> <pre><code>nums = someString./\d+|pi|e/gi </code></pre> <p>The next part is going to be hard but to boil it down to is core concept, you need to look for key words such as 'square root', 'times', or 'plus'. You should do this word by word going left to right. For example if a user inputs</p> <pre><code>What is 5 plus 3 minus 8? </code></pre> <p>you should detect the plus before the minus, while if this is inputted</p> <pre><code>What is 5 minus 3 plus 8? </code></pre> <p>You should detect the minus before the plus.</p> <p>For operations that uses two numbers you need to take the first two numbers that you found and do the operation and replace the two numbers with the result. I am trying to use reverse polish notation if you do not quite understand what I am trying to do, look it up if do not know what it is.</p> <p>I hope I understood your question correctly and provided some help to coming to a solution because what you asked is very hard but seems like fun. Good luck. Also as a warning I am not considering order of operations in my response.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload