Font size
WorksheetsAuto-évaluation 2 Sprint 2
Total questions: 50
Worksheet time: 1hrs 17mins
Which method adds an element as the last child of a specified element?
innerHTML()
createElement()
insertBefore()
appendChild()
How do you select all elements with the class button in JavaScript?
document.querySelector('.button')
document.getElementsByTagName('button')
document.getElementByClass('button')
document.querySelectorAll('.button')
What does event.preventDefault() do?
Prevents the default action of an event
Deletes an event handler
Stops all JavaScript execution
Stops the DOM from loading
Which of these does not change the text of an HTML element in JavaScript?
element.innerHTML = "Hello"
element.innerText("Hello")
element.textContent = "Hello"
element.value = "Hello"
What is the correct way to create a new HTML element in JavaScript?
document.addElement("div")
document.createElement("div")
document.newElement("div")
document.setElement("div")
How do you add an event listener for a 'click' event?
addEventListener('click', element)
element.addListner('click', funtion)
element.onClick(function)
element.addEventListener('click', function)
Which JavaScript method is used to remove an element from the DOM?
removeChild()
deleteNode()
removeElement()
deleteElement()
What does document.querySelector('div') select?
All <div> elements
The first <div> element
Collection of elements
Elements with the id 'div'
What does the innerText property do?
Changes the element's HTML structure
Adds a child element to the DOM
Retrieves an attribute value
Sets or returns the visible text of an element
Which method creates a new HTML element in JavaScript?
element.innerHtml()
element.appendChild()
document.addElement()
document.createElement()
How can you add a class to an HTML element?
element.addClass('new-class')
element.classList.add('new-class')
element.className = 'new-class'
element.classList('new-class')
How can you find the parent of an HTML element in JavaScript?
element.parent()
element.parent.find()
element.getParent()
element.parentNode
What is the correct syntax to add a comment in JavaScript?
<!-- comment -->
\\ comment
// comment
/*comment*/
How do you add inline style to an element in JavaScript?
element.style.color = 'blue'
element.color = 'blue'
element.addStyle('color: blue')
element.css('color', 'blue')
Which event is triggered when a form is submitted?
onclick
onsubmit
onchange
onhover
Which function converts a string str to a number in JavaScript?
toInteger(str)
parseInt(str)
+str
Number(str)
What does this code log?
"null"
"undefined"
"string"
"object"
What will be the result of this code?
5
6
Throws an error
undefined
What will be displayed in the console?
undefined
0
3
null
What will this code log to the console?
True
False
What will be the result of this code?
"c"
"a"
"S"
undefined
What does this code log to the console?
"p"
null
"div"
"Hello"
What is the result of this code?
"World"
"Hello "
"Hello"
" "
What will be printed in the console?
[1, 2, 3]
[1, 2, 3, 4]
Throws an error
null
What will this code output?
true
false
1
2
What will the following code output?
15
105
NaN
115
What does this code display in the console?
null
"DIV"
"HTML"
"BODY"
What will this code print?
3
2
cherry
banana
What does this code output?
undefined
"e"
"H"
Hello
What will be the result of this code?
Error
BANANA
BANA
NaN
What will be the output here?
"Hello"
"World"
"e"
"o"
What does this code log?
[5, 6]
[7]
5
7
Using let to declare a variable prevents redeclaration of that variable in different scope.
True
False
In JavaScript, functions can return other functions.
True
False
You can use const to declare a variable and then change its properties if it’s an object or array.
True
False
The appendChild method can insert multiple nodes at once.
True
False
In JavaScript, NaN === NaN evaluates to true.
True
False
In the DOM, comments are considered nodes.
True
False
In JavaScript, NaN (Not a Number) is a type of number.
True
False
In JavaScript, let and var are exactly the same.
True
False
predict output
25
26
age: 25
age: 26
predict output
{ x: 2, y: { x: 1 } }
undefined
3
syntax error
Write a function filterAdults(users) that returns only users whose age >= 18.
const users = [{name:'Sara',age:17},{name:'Ali',age:22},{name:'Redone',age:16}];
const people = [{name:'Nora'},{name:'Youssef'},{name:'Amina'}];
Write code that produces ['Nora','Youssef','Amina'].
Sort the following array ascending by price:
const product = [{title: "Book1", price:30},{title: "Book2", price:10},{title: "Book3", price:20}];
const students = [{name:'Aya'},{name:'Karim'}];
Write code to add a new property active: true to each object (without creating a new array).
Write code to find the average rating per restaurant.
Write a code that gets the names of restaurants rated 5 by any user.
Write code to return restaurant with most reviews
Write code to show all elements of array
const people = [{id:1,name:'Ali'},{id:2,name:'Nora'},{id:3,name:'Sara'}];
