Sololearn JavaScript course DOM & Events answers

Here are all the questions and answers that I hope will help you learn JavaScript course.
Sololearn JavaScript course Overview answers
Sololearn JavaScript course Basic Concepts answers
Sololearn JavaScript course Conditionals and Loops answers
Sololearn JavaScript course Functions answers
Sololearn JavaScript course Objects answers
Sololearn JavaScript course Core Objects answers
Sololearn JavaScript course ECMAScript 6 answers

45.1 Lesson

What is DOM?

Question:

The DOM
What is DOM?

Answer:

Document Object Model

Question:

DOM Tree
In the following HTML, which element is the parent of h1?

<body>
  <p>
    <h1>Hi</h1>
  </p>
</body>

Answer:

p

Question:

The document Object
Select all that apply:

Answer:

The document object is the root of the DOM
innerHTML is a property

46.1 Lesson

Selecting Elements

Question:

Selecting Elements
Fill in the blanks to select the element with id="text" and change its content to "Hi".

Answer:

var ob = document.getElementById("text");
ob.innerHTML = "Hi";

Question:

Selecting Elements
Fill in the blanks to select all div elements and alert the content of the third div.

Answer:

var arr = document.getElementsByTagName("div");
alert(arr[2].innerHTML);

Question:

Working with DOM
Can a node in the DOM have multiple parent nodes?

Answer:

No

47.1 Lesson

Changing Elements

Question:

Changing Attributes
Fill in the blanks to select all images of the page and change their src attribute.

Answer:

var arr = document.
getElementsByTagName("img");
for(var x=0; x < arr.length; x++) {
arr[x].src = "demo.jpg";
}

Question:

Changing Style
Fill in the blanks to change the background color of all span elements of the page.

Answer:

var s = document.getElementsByTagName("span");
for (var x = 0; x < s.length; x++) {
  s[x].style.backgroundColor = "#33EA73";
}

48.1 Lesson

Adding & Removing Elements

Question:

Creating Elements
Drag and drop from the options below to add a new <li> element to the unordered list with id="list".

Answer:

var el = document.createElement("li");
var txt = document.createTextNode("B");
el.appendChild(txt);
var ul = document.getElementById("list");
ul.appendChild(el);

Question:

Removing Elements
Drag and drop from the options below to remove the node element from the page (par is node's parent).

Answer:

var par = document.getElementById("par");
var node = document.getElementById("node");
par.removeChild(node);

Question:

Replacing Elements
Which method is used to replace nodes?

Answer:

replaceChild

49.1 Lesson

Creating Animations

Question:

Animations
To create an animation relative to a container, the position attribute for the container should be set to:

Answer:

relative

Question:

Animations
What is the interval for this timer? var t = setInterval(func, 10000);

Answer:

10 seconds

Question:

Animations
Which function is used to stop a setInterval timer?

Answer:

clearInterval

50.1 Lesson

Handling Events

Question:

Events
The type of function that executes when an event occurs is called:

Answer:

event handler

Question:

Handling Events
Fill in the blanks to call func() when the button is clicked.

Answer:

<button onclick="func()">
  Click Here
</button>

Question:

Events
Drag and drop from the options below to call the clear() function after body is loaded.

Answer:

<body onload="clear()">
</body>

Question:

Event Listeners
Can multiple event handlers be added to a single element?

Answer:

Yes

51.1 Lesson

Event Propagation

Question:

Event Propagation
A paragraph is inside a div element. You want the paragraph’s click event to be handled first. You should use:

Answer:

Bubbling

Question:

Capturing vs. Bubbling
Drag and drop from the options below to handle the click event and use capturing propagation.

Answer:

x.addEventListener("click", func, true);

52.1 Lesson

Creating an Image Slider

Question:

Image Slider
Fill in the blanks to define an array.

Answer:

var arr = ['A', 'B', 'C'];

Question:

Image Slider
What will be the content of the paragraph after the user clicks on it twice?

<p id='txt' onclick='test();'>20</p>
<script>
  function test() {
    var x=document.getElementById('txt');
    var n = x.innerHTML; x.innerHTML = n/2;
  }
</script>

Answer:

5

53.1 Lesson

Form Validation

Question:

Form Validation
The form will submit to its action if onsubmit returns:

Answer:

true

54.1 Lesson

Module 7 Quiz

Question:

Fill in the blanks to change the content of all paragraph tags of the page to "SoloLearn".

Answer:

var arr = document.getElementsByTagName("p");
for(var x=0; x < arr.length; x++){
  arr[x].innerHTML="SoloLearn";
}

Question:

What is the output of this code?

<div id="test">
  <p>some text</p>
</div>
<script>
  var el=document.getElementById("test");
  alert(el.hasChildNodes());
</script>

Answer:

true

Question:

Drag and drop from the options below to change the color of the paragraph with id="p2" to red.

Answer:

<script>
  var d = document.getElementById("p2");
  d.style.color="red";
</script>

Question:

Can you handle multiple events on the same HTML element?

Answer:

Yes

Question:

Fill in the blanks to alert a message when the button is clicked.

Answer:

<button onclick="msg()">Click me</button>
<script>
  function msg() {
    alert("Hi!");
  }
</script>

Question:

Display an alert when the mouse pointer is over the div tag:

Answer:

<div onmouseover="alert('Hi!');">
  put the mouse pointer over me
</div>