# Javascript Final Quiz¶

For the following questions, you may use the textbook or your notes. You may not google other references. You have 30 minutes to complete both parts of the quiz. Make sure that you complete the multiple choice questions first, and click “Finish Exam” before you go on to do the coding question.

Q-1: Inside which HTML tag do we put Javascript code?
• <script>
• Yes
• <scripting>
• close
• <style>
• style is for CSS
• <javascript>
• no
Q-2: Which is the correct statement to change the following: <p id="demo">This is a demonstration.</p>
• #demo.innerHTML = "Hello World!";
• No, this is an error
• document.appendChild("p").innerHTML = "Hello World!";
• No
• document.getElement("p").innerHTML = "Hello World!";
• No
• document.querySelector("#demo").innerHTML = "Hello World!";
• Yes!
Q-3: Which event occurs when the user clicks on an HTML element?
• onchange
• No, this would work only with input elements
• onclick
• Yes
• onmouseover
• No, this event does not require a click
• onmouseclick
• No, this is not an event
Q-4: Which javascript statement correctly creates a new entry for a list?
• document.body.ol.innerHTML = "<li>"
• No, There is no document.body.ol
• myLi = "#newli"
• This just assigns a string to a variable
• document.createElement("li")
• Yes
• myOl.appendChild("li")
• No, appendChild does not create an element
Q-5: An external JavaScript file must contain the <script> tag.
• True
• No Feedback
• False
• No Feedback
Q-6: How do you write “Hello World” in an alert box?
• msg("Hello World");
• No, there is no msg function
• console.log("Hello World");
• This adds a message to the javascript console
• There is no alertBox function
• Yes!
Q-7: How do you create a function in JavaScript?
• myFunction = function()
• Yes
• myFunction()
• No, this calls myFunction
• function:myFunction()
• No, the : is wrong
• <script>function = {}</script>
• No, this is syntactically all wrong
Q-8: Which statement correctly adds a tr element named myTr to the DOM tree?
• There is no addParent function
• document.body.innerHTML = "<tr><tr></tr></td>"
• No, this changes the entire body
• myRow.appendChild(myTr);
• Yes
• myTr.appendChild(myRow);
• No, you have parent and child backward
Q-9: What is the correct syntax for referring to an external script called “xxx.js”?
• <script name="xxx.js">
• No, name is mainly used with input tags
• <script src="xxx.js">
• Yes
• <script href="xxx.js">
• href is used with the link tag
• No, link is used for including css

Q-10: Given the following HTML source, what is the parent of the element with the selector “#a4”

<body>
<table id="a1">
<tr id="a2">
<td id="a3">Hello</td>
<td id="a4"><img id="a5" src="hello.jpg"></td>
</tr>
</table>
</body>

• a1
• No, a1 is the grand parent
• a2
• Yes
• a3
• No, a3 is a sibling
• a5
• No, a5 is the child of a4

## Programming Question¶

Write a function that each time it is clicked will do the following:

1. Turn the background of the page light blue.
2. Add another H1 to the page that says “So Long 130”
3. Changes the font color for the H1 to red

By each time, I mean that if the button is clicked 10 times there should be 10 H1’s on the page.