Javascript is a scripting language that can be used to apply more interactive code to your website, it also makes accessing objects within a page much simpler.
Javascript can either be placed in a file with a .js extension or placed within html using the script tags.
HTML Code:
<script type="text/javascript"> document.write("My first piece of Javascript!"); </script>
HTML Code:
<script type="text/javascript"> var firstValue = "test1"; var secondValue = "test2"; document.write(firstValue + ' - ' + secondValue); </script>
test1 - test2
Within the document.write you will notice there are two plus signs, this indicates that after the variable there is more content to follow, if we just wished to print the two variable contents without the hyphen then we would only need one plus and no single quote.
Try saving the following as a .html file and see if you can change the inputs and outputs to make sure your confident with printing variables and text.
HTML Code:
<html> <body> <script type="text/javascript"> var firstValue = "This is a test"; var secondValue = "to check I have learnt well"; document.write(firstValue + ' ' + secondValue); </script> </body> </html>










Menu
Category