For this assignment, you are to generate a message to HTMl using Javascript. Your message will be in the form of a math equation. ex. 1 + 1 = 2
- In the body of your page create an empty HTML tag: ex. <p id="example"></p>
- use document.getElementById("example").innerHTML =
- Make sure that the ID on both lines matches EXACTLY and remember that IDs must be unique.
- Putting the equation together requires you to combine a string with an operation
- A string will be contained within double quotes ""
- An operation will be contained within parenthesis ()
- Strings and operations can be combined by 'adding' them together with a + symbol. eg. "This string" + (This Operation) + "Another string" + "As many strings" + (or operations) + "As you wish."
- Get comfortable with this, you will do it A LOT!
- Write out your string. ex. "2 + 2 ="
- 'Add' your operation. ex. + (2+2)
- The complete line in Javascript should look like: document.getElementById("example").innerHTML = "2 + 2 = " + (2 + 2);
Your website should resemble the example below:
back to index