You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Let's use `eval` to calculate the maths expression:
2
+
3
+
```js demo run
4
+
let expr =prompt("Type an arithmetic expression?", '2*3+2');
5
+
6
+
alert( eval(expr) );
7
+
```
8
+
9
+
The user can input any text or code though.
10
+
11
+
To make things safe, and limit it to arithmetics only, we can check the `expr` using a [regular expression](info:regular-expressions), so that it only may contain digits and operators.
0 commit comments