an h1 element containing "Assignment 4"
an h2 element containing the name of your favourite sport or hobby
a p element with a description of the sport or hobby you chose (just a sentence or two)
2. Create a JavaScript file named script.js. Associate this file with your HTML file using the best
practices taught in class.
3. In the JavaScript file do the following:
create a variable that contains your name
console.log the value of this variable
include the following code in your JavaScript file. Don't worry about how it works for now,
we will cover this in the next module, but it will replace the text in the h2 element when
viewing the webpage. (Use the variable name that you created instead of myName.)
document.querySelector('h2').textContent = myName;
4. Open your HTML file in a web browser. Check the console for you output and the web page for
the replacement text on the page.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<h1>Assignment 4</h1>
<h2>Football</h2>
<p>Spectacular and engrossing sport</p>
<script src="script.js"></script>
</body>
</html>
var myName = "Steve";
console.log(myName);
document.querySelector('h2').textContent = myName;
Comments
Leave a comment