Skip to content

Commit 8b567f5

Browse files
committed
Add solution file
1 parent 4e7eaba commit 8b567f5

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
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

Comments
 (0)