document.write - Javascript using document write -
so i'm trying print text, , defined variables using document.write function in notepad++ , javascript. can't show in web browser when open .html file. i'm new javascript. here's code.
<html> <body> <script> var x == 23 ; var y == 55 ; var z == var x + var y ;</script> <script> document.write("the sum of x + y" + z +<br>);</script> <script> document.write("the sum of x + y = " + z + <br>);</script> <script> document.write("the sum of x + y = " + ( x + y) + <br>);</script> <script> var x = "bob dylan" , var y = "is enrolled in cop 2500" , var z = "with professor whiting, best!"</script> <script> document.write( x + y + z);</script> </body> </html>
<html> <body> <script> var x = 23 ; var y = 55 ; var z = x + y ; document.write("the sum of x + y = " + z + '<br>'); document.write("the sum of x + y = " + z + '<br>'); document.write("the sum of x + y = " + ( x + y) + '<br>'); x = "bob dylan" , y = "is enrolled in cop 2500" , z = "with professor whiting, best!" document.write( x + y + z); </script> </body> </html>
ok, let's go through changes made here. first off, blocks of script need opening tag, , closing tag. don't need create new script block every line.
next, when assigning value variable use 1 equals sign. == comparison operator.
next, html writing page inside script tag, needs in quotes: '<br />'
finally, once variable has been created, don't need re-initialize var again. instance, create variable using var x = 0
. can use variable later saying x
;
Comments
Post a Comment