I’m seeking to advance my knowledge of Javascript with a book. But I can’t figure out why the alert() message does not fire:
<script type="text/Javascript">
var result = 2 * 4;
var message = "2 times 4 = " result;
alert(message);
</script>
I’m seeking to advance my knowledge of Javascript with a book. But I can’t figure out why the alert() message does not fire:
<script type="text/Javascript">
var result = 2 * 4;
var message = "2 times 4 = " result;
alert(message);
</script>
You have two previous instructions. Which one do you think is the wrong one?
The first one evaluates to a number: 2*4. The second one evaluates to a… what?
Here is how I understand it:
var result = 2 * 4; // this should give me 8.
var message = "2 times 4 = " result; // this should give me the string of 2 times 4 and concatenate the result of 8.
alert(message); // the var above of string and “8” should appear in the alert box.
Hi there,
The concatenation is wrong. You’re missing an operator
var message = "2 times 4 = " <something missing here> result;
I see it! I need a plus sign.
var result = 2 * 4;
var message = "2 times 4 = " + result;
alert(message);
Thank you very much!
No probs