Fix the addition
Here’s a code that asks the user for two numbers and shows their sum.
It works incorrectly. The output in the example below is
12 (for default prompt values).
Why? Fix it. The result should be
The reason is that prompt returns user input as a string.
So variables have values
What we should do is to convert strings to numbers before
+. For example, using
Number() or prepending them with
For example, right before
Or in the
Using both unary and binary
+ in the latest code. Looks funny, doesn’t it?