Learn Create Your Own Split Screen

Next Page

The problem is that when you use the plus operator on a mixture of numbers and strings, Javascript treats everything as a string.

Apples contains 3, and oranges contains 5.

Expression Result
apples  +  oranges 8
"total is " + apples  +  oranges "total is 35"

The solution is simply to use parentheses to force the numeric part of the expression to be evaluated first.

Expression Result
"total is " + (apples  +  oranges) "total is 8"