Adding numbers and strings

I’m brand new and need help with this problem. Can someone explain to me how to correctly add the string and numbers so that the numbers also add up?

It would come out to The result is: 1020

<!DOCTYPE html>

<h2>JavaScript Numbers</h2>

<p>A common mistake is to expect this result to be 30:</p>

<p id=“demo”></p>

var x = 10;
var y = 20;
document.getElementById(“demo”).innerHTML =
"The result is: " + x + y;


It may work if you add parenthesis around the variables that hold the numbers, or you will need to create a different variable that holds the result of the sum and concatenate that to the string

1 Like

Ahh the parenthesis worked. But using another var for the string didn’t work, unless i added the parenthesis again. Thank you!

Not sure what you tried, but the following is what was suggested:

var x = 10;
var y = 20;
var sum = x + y;  
document.getElementById('demo').innerHTML = "The result is: " + sum;
1 Like

Oh I see, that makes sense. thank you!
What i thought she meant and did was make a var holding the string "The result is: " which didnt work