Reputation: 35
I know that this has to be the simplest thing of all time, but I'm a beginner here. Why do I get a syntax error when I run
<script type="text/javascript" language="JavaScript">
document.write(10 / 2 + "<br />"); //Divide 10 by 5 to get 2
</script>
I know that "/" is the division symbol, but for some weird reason it keeps throwing off Dreamweaver
Upvotes: 0
Views: 267
Reputation: 23416
Looks like Dreamweaver can't do automatic type casting when concatenating numbers to strings. Hence you need to do the type coercion yourself:
document.write((10 / 2).toString(10) + "<br />");
Upvotes: 0
Reputation: 2113
<script type="text/javascript" language="JavaScript">
//is better that add a variable
var p=10/5;
document.write(p + "<br />"); //Divide 10 by 5 to get 2
//or document.write(float(10/5) + "<br />"); //Divide 10 by 5 to get 2
</script>
Upvotes: 2