The following is a template that needs to be completed using JavaScript. Some ad
ID: 3687413 • Letter: T
Question
The following is a template that needs to be completed using JavaScript. Some additional notes: You must use the DOM to write to the page (use firstChild.nodeValue to write to the quote of the day and the date (day). You must the DOM (createTextNode(), createElement(), appendChild()) to loop through and to display all of the quotes on the page. When completed, the page should look something like the following:
</html>
<!DOCTYPE html> <!-- jsjqas04_start_file.html This file contains the starting code that you can use for Assignment 4. --> <html> <head> <meta charset="utf-8"> <title>JSJQ Assignment 4 - Arrays / Date Starter File</title> <style> body{ font-family: arial, sans-serif; font-size: 100%; } form{ margin-top: 50px; } </style> <script> //************************************************************ // 1: define variables for today's date, //************************************************************ //************************************************************ // 2: define an array to hold the day names //************************************************************ //************************************************************ // 3: define an array to hold the daily quotes //************************************************************ //************************************************************ // 4: loop through all of the quotes // and write the quotes to the page. Use DOM methods // to write to the page. //************************************************************ //************************************************************ // 5: create a window.onload function to format and display // the current day name. // // Display the quote for the day. // // //************************************************************ </script> <!-- The following are sample quotes. You can use other quotes --> <!-- of your choosing if you want to. --> <!-- Ability is nothing without opportunity - Napoleon Bonaparte Nothing happens unless first we dream - Carl Sandburg Believe you can and you're halfway there - Theodore Roosevelt A place for everything, everything in its place - Benjamin Franklin Don't let the fear of striking out hold you back - Babe Ruth We can't help everyone, but everyone can help someone - Ronald Reagan With self-discipline most anything is possible - Theodore Roosevelt --> </head> <body> <h1>Quote of the Day</h1> </body></html>
Explanation / Answer
JavaScript is the world's most popular programming language. It is the language for HTML, for the web, for servers, PCs, laptops, tablets, phones, and more. You can write directly to HTML
<script>
document.write("<h1>This is a heading</h1>");
document.write("<p>This is a paragraph.</p>");
</script>
You will often see document.getElementById("some id"). This is defined in the HTML DOM. The DOM (Document Object Model) is the official W3C standard for accessing HTML elements. You will find several chapters about the HTML DOM in this tutorial.
<!DOCTYPE html>
<body>
<h1>My First JavaScript</h1>
<p id="demo">JavaScript can change the content of an HTML element.</p>
<script>
function myFunction()
{
x=document.getElementById("demo"); // Find the element
x.innerHTML="Hello JavaScript!"; // Change the content
}
</script>
<button type="button">Click Me!</button>
</body></html>
<!DOCTYPE html><html><head>
<script>
function displayDate()
{
document.getElementById("demo").innerHTML=Date();
}
</script></head>
<body>
<h1>My First JavaScript</h1>
<p id="demo">This is a paragraph.</p>
<button type="button">Display Date</button>
</body></html>
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.