wip: add more questions

chore/javascript
Arik Chakma 1 year ago
parent c70ee5c5f3
commit aee10fac37
  1. 8
      src/data/question-groups/javascript/content/measure-dimensions.md
  2. 25
      src/data/question-groups/javascript/content/merge-arrays.md
  3. 9
      src/data/question-groups/javascript/content/remove-element.md
  4. 5
      src/data/question-groups/javascript/content/scroll-to-top.md
  5. 20
      src/data/question-groups/javascript/javascript.md

@ -0,0 +1,8 @@
You can use `getBoundingClientRect` method to get the dimensions of an element.
```js
const roadmapWrapper = document.querySelector('.roadmap-wrapper');
const dimensions = roadmapWrapper.getBoundingClientRect();
console.log(dimensions); // DOMRect { x: 8, y: 8, width: 784, height: 784, top: 8, right: 792, bottom: 792, left: 8 }
```

@ -0,0 +1,25 @@
Yes, you can merge multiple arrays into one array using the `concat()` method, or the spread operator `...`.
## concat()
The `concat()` method is used to merge two or more arrays. This method does not change the existing arrays, but instead returns a new array.
```js
const arr1 = [1, 2, 3];
const arr2 = [4, 5, 6];
const arr3 = arr1.concat(arr2);
console.log(arr3); // [1, 2, 3, 4, 5, 6]
```
## Spread operator
The spread operator `...` is used to expand an iterable object into the list of arguments.
```js
const arr1 = [1, 2, 3];
const arr2 = [4, 5, 6];
const arr3 = [...arr1, ...arr2];
console.log(arr3); // [1, 2, 3, 4, 5, 6]
```

@ -0,0 +1,9 @@
To remove a DOM element, you can use the `remove` or `removeChild` method of the `Node` interface.
```js
const roadmapWrapper = document.querySelector('.roadmap-wrapper');
const roadmapTitle = document.querySelector('#roadmap-title');
roadmapWrapper.removeChild(roadmapTitle);
roadmapWrapper.remove();
```

@ -0,0 +1,5 @@
In order to scroll to the top of the page, we can use the `scrollTo` method.
```js
window.scrollTo(0, 0);
```

@ -368,4 +368,24 @@ questions:
topics:
- 'DOM'
- 'Beginner'
- question: How to remove an Element from DOM?
answer: remove-element.md
topics:
- 'DOM'
- 'Beginner'
- question: How to scroll to the top of the page using JavaScript?
answer: scroll-to-top.md
topics:
- 'DOM'
- 'Beginner'
- question: How to measure dimensions of an Element?
answer: measure-dimensions.md
topics:
- 'DOM'
- 'Beginner'
- question: Can you merge multiple arrays in JavaScript?
answer: merge-arrays.md
topics:
- 'Core'
- 'Intermediate'
---

Loading…
Cancel
Save