Basic JavaScript Functions
Demo 1
The first basic JavaScript method is getElementById(). In this example the ID is 'demo-1' and the the trigger is onclick. The message is unhidden once the button is clicked.
Demo 2
In this example the ID is 'demo-2'. Clicking on the button will replace this first paragraph with a second paragraph. In this example a function is called from an external JavaScript file using the myFunction() method
This is the first paragraph
Demo 3
In this demo a function is used to convert celsuis to farenheit. The celsius temperature is set at 30.
Demo 4
In this example the id is 'demo-3' and it uses an output called inner.HTML to insert the answer inside a HTML tag. For this to work the id must be read before the script.
The answer is
This will give us the calculation of 6 + 7.
Demo 5
This example is 'demo-4' and it is the same as demo-3 expect that the script it reads an external script called calculation.js
This will give us the calculation of 10 + 20
The answer is
This will give us the calculation of 10 + 20
The answer is
Demo 6
Displaying data from an external JavaScript file on a page using let and getElementById
Demo 6
Displaying data from an external JavaScript file on a page using Const and getElementById