wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Auto-évaluation 2 Sprint 2

Total questions: 50

Worksheet time: 1hrs 17mins

Name
Class
Date
1.

Which method adds an element as the last child of a specified element?

a)

innerHTML()

b)

createElement()

c)

insertBefore()

d)

appendChild()

2.

How do you select all elements with the class button in JavaScript?

a)

document.querySelector('.button')

b)

document.getElementsByTagName('button')

c)

document.getElementByClass('button')

d)

document.querySelectorAll('.button')

3.

What does event.preventDefault() do?

a)

Prevents the default action of an event

b)

Deletes an event handler

c)

Stops all JavaScript execution

d)

Stops the DOM from loading

4.

Which of these does not change the text of an HTML element in JavaScript?

a)

element.innerHTML = "Hello"

b)

element.innerText("Hello")

c)

element.textContent = "Hello"

d)

element.value = "Hello"

5.

What is the correct way to create a new HTML element in JavaScript?

a)

document.addElement("div")

b)

document.createElement("div")

c)

document.newElement("div")

d)

document.setElement("div")

6.

How do you add an event listener for a 'click' event?

a)

addEventListener('click', element)

b)

element.addListner('click', funtion)

c)

element.onClick(function)

d)

element.addEventListener('click', function)

7.

Which JavaScript method is used to remove an element from the DOM?

a)

removeChild()

b)

deleteNode()

c)

removeElement()

d)

deleteElement()

8.

What does document.querySelector('div') select?

a)

All <div> elements

b)

The first <div> element

c)

Collection of elements

d)

Elements with the id 'div'

9.

What does the innerText property do?

a)

Changes the element's HTML structure

b)

Adds a child element to the DOM

c)

Retrieves an attribute value

d)

Sets or returns the visible text of an element

10.

Which method creates a new HTML element in JavaScript?

a)

element.innerHtml()

b)

element.appendChild()

c)

document.addElement()

d)

document.createElement()

11.

How can you add a class to an HTML element?

a)

element.addClass('new-class')

b)

element.classList.add('new-class')

c)

element.className = 'new-class'

d)

element.classList('new-class')

12.

How can you find the parent of an HTML element in JavaScript?

a)

element.parent()

b)

element.parent.find()

c)

element.getParent()

d)

element.parentNode

13.

What is the correct syntax to add a comment in JavaScript?

a)

<!-- comment -->

b)

\\ comment

c)

// comment

d)

/*comment*/

14.

How do you add inline style to an element in JavaScript?

a)

element.style.color = 'blue'

b)

element.color = 'blue'

c)

element.addStyle('color: blue')

d)

element.css('color', 'blue')

15.

Which event is triggered when a form is submitted?

a)

onclick

b)

onsubmit

c)

onchange

d)

onhover

16.

Which function converts a string str to a number in JavaScript?

a)

toInteger(str)

b)

parseInt(str)

c)

+str

d)

Number(str)

17.

What does this code log?

a)

"null"

b)

"undefined"

c)

"string"

d)

"object"

18.

What will be the result of this code?

a)

5

b)

6

c)

Throws an error

d)

undefined

19.

What will be displayed in the console?

a)

undefined

b)

0

c)

3

d)

null

20.

What will this code log to the console?

a)

True

b)

False

21.

What will be the result of this code?

a)

"c"

b)

"a"

c)

"S"

d)

undefined

22.

What does this code log to the console?

a)

"p"

b)

null

c)

"div"

d)

"Hello"

23.

What is the result of this code?

a)

"World"

b)

"Hello "

c)

"Hello"

d)

" "

24.

What will be printed in the console?

a)

[1, 2, 3]

b)

[1, 2, 3, 4]

c)

Throws an error

d)

null

25.

What will this code output?

a)

true

b)

false

c)

1

d)

2

26.

What will the following code output?

a)

15

b)

105

c)

NaN

d)

115

27.

What does this code display in the console?

a)

null

b)

"DIV"

c)

"HTML"

d)

"BODY"

28.

What will this code print?

a)

3

b)

2

c)

cherry

d)

banana

29.

What does this code output?

a)

undefined

b)

"e"

c)

"H"

d)

Hello

30.

What will be the result of this code?

a)

Error

b)

BANANA

c)

BANA

d)

NaN

31.

What will be the output here?

a)

"Hello"

b)

"World"

c)

"e"

d)

"o"

32.

What does this code log?

a)

[5, 6]

b)

[7]

c)

5

d)

7

33.

Using let to declare a variable prevents redeclaration of that variable in different scope.

a)

True

b)

False

34.

In JavaScript, functions can return other functions.

a)

True

b)

False

35.

You can use const to declare a variable and then change its properties if it’s an object or array.

a)

True

b)

False

36.

The appendChild method can insert multiple nodes at once.

a)

True

b)

False

37.

In JavaScript, NaN === NaN evaluates to true.

a)

True

b)

False

38.

In the DOM, comments are considered nodes.

a)

True

b)

False

39.

In JavaScript, NaN (Not a Number) is a type of number.

a)

True

b)

False

40.

In JavaScript, let and var are exactly the same.

a)

True

b)

False

41.

predict output

a)

25

b)

26

c)

age: 25

d)

age: 26

42.

predict output

a)

{ x: 2, y: { x: 1 } }

b)

undefined

c)

3

d)

syntax error

43.

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}];

4 lines
44.

const people = [{name:'Nora'},{name:'Youssef'},{name:'Amina'}];

Write code that produces ['Nora','Youssef','Amina'].

4 lines
45.

Sort the following array ascending by price:

const product = [{title: "Book1", price:30},{title: "Book2", price:10},{title: "Book3", price:20}];

4 lines
46.

const students = [{name:'Aya'},{name:'Karim'}];

Write code to add a new property active: true to each object (without creating a new array).

4 lines
47.

Write code to find the average rating per restaurant.

4 lines
48.

Write a code that gets the names of restaurants rated 5 by any user.

4 lines
49.

Write code to return restaurant with most reviews

4 lines
50.

Write code to show all elements of array
const people = [{id:1,name:'Ali'},{id:2,name:'Nora'},{id:3,name:'Sara'}];

4 lines