mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-05-28 18:26:54 +00:00
refactor(curriculum): asynchronous quiz (#58509)
Co-authored-by: Tom <20648924+moT01@users.noreply.github.com> Co-authored-by: Sem Bauke <sem@freecodecamp.org> Co-authored-by: Dario-DC <105294544+Dario-DC@users.noreply.github.com>
This commit is contained in:
+124
-80
@@ -21,15 +21,15 @@ What is asynchronous programming?
|
||||
|
||||
#### --distractors--
|
||||
|
||||
A way to execute code in a sequential order.
|
||||
A method for executing code sequentially.
|
||||
|
||||
---
|
||||
|
||||
A technique to handle errors in synchronous code.
|
||||
A technique to handle errors in your code.
|
||||
|
||||
---
|
||||
|
||||
A way to guarantee task order.
|
||||
A way to make network requests, typically to retrieve or send data to the server.
|
||||
|
||||
#### --answer--
|
||||
|
||||
@@ -39,23 +39,23 @@ A method to execute code concurrently without blocking the main thread.
|
||||
|
||||
#### --text--
|
||||
|
||||
What does the `async` attribute do when used in a `<script>` tag?
|
||||
What is a thread?
|
||||
|
||||
#### --distractors--
|
||||
|
||||
It allows the script to be executed after the HTML document has been completely parsed.
|
||||
A function used to retrieve data from the server.
|
||||
|
||||
---
|
||||
|
||||
It ensures the script runs in a synchronous manner.
|
||||
A program that executes JavaScript code in a web browser.
|
||||
|
||||
---
|
||||
|
||||
It delays the script execution until the browser is idle.
|
||||
A special type of function that is passed as an argument to another function.
|
||||
|
||||
#### --answer--
|
||||
|
||||
The script is downloaded in parallel with parsing the page and executed as soon as it is available.
|
||||
A sequence of instructions that can be executed independently of the main program flow.
|
||||
|
||||
### --question--
|
||||
|
||||
@@ -105,23 +105,39 @@ Which `HTTP` method is used to send data to a server for processing?
|
||||
|
||||
#### --text--
|
||||
|
||||
What does the `res.json()` method do in Express.js?
|
||||
Which of the following is the correct way to fetch data from an API?
|
||||
|
||||
#### --distractors--
|
||||
|
||||
It retrieves data from a JSON file.
|
||||
```js
|
||||
fetch('https://api.example.com/data')
|
||||
.accept(response => response.json())
|
||||
.accept(data => console.log(data))
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
It parses a JSON string into a JavaScript object.
|
||||
```js
|
||||
fetch('https://api.example.com/data')
|
||||
.allow(response => response.json())
|
||||
.allow(data => console.log(data))
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
It sends raw JSON as a response without any processing.
|
||||
```js
|
||||
fetch('https://api.example.com/data')
|
||||
.send(response => response.json())
|
||||
.send(data => console.log(data))
|
||||
```
|
||||
|
||||
#### --answer--
|
||||
|
||||
It converts a JavaScript object to a JSON string and sends it as a response.
|
||||
```js
|
||||
fetch('https://api.example.com/data')
|
||||
.then(response => response.json())
|
||||
.then(data => console.log(data))
|
||||
```
|
||||
|
||||
### --question--
|
||||
|
||||
@@ -131,15 +147,15 @@ What is a promise in JavaScript?
|
||||
|
||||
#### --distractors--
|
||||
|
||||
A way to synchronize multiple operations.
|
||||
A way to synchronize multiple operations when working with the Fetch API.
|
||||
|
||||
---
|
||||
|
||||
A callback function that runs after an operation.
|
||||
A special type of callback function that you must use in all higher order functions.
|
||||
|
||||
---
|
||||
|
||||
A technique to handle errors in asynchronous code.
|
||||
A technique used to handle errors when you work with the Fetch API.
|
||||
|
||||
#### --answer--
|
||||
|
||||
@@ -153,25 +169,25 @@ What does promise chaining allow you to do?
|
||||
|
||||
#### --distractors--
|
||||
|
||||
Execute multiple asynchronous operations in parallel.
|
||||
Allows you to execute multiple synchronous operations in parallel.
|
||||
|
||||
---
|
||||
|
||||
Handle synchronous operations more efficiently.
|
||||
Allows you to handle synchronous operations more efficiently.
|
||||
|
||||
---
|
||||
|
||||
Retry failed operations automatically.
|
||||
Allows you to retry failed operations automatically.
|
||||
|
||||
#### --answer--
|
||||
|
||||
Pass the result of one promise to the next.
|
||||
Allows you to perform a sequence of asynchronous operations one after the other.
|
||||
|
||||
### --question--
|
||||
|
||||
#### --text--
|
||||
|
||||
Which method is used to handle successful completion of a promise?
|
||||
Which method is used to handle a successful completion of a promise?
|
||||
|
||||
#### --distractors--
|
||||
|
||||
@@ -215,29 +231,29 @@ Which method is used to handle errors in a promise chain?
|
||||
|
||||
#### --text--
|
||||
|
||||
What is the use of the `.finally()` method in a promise?
|
||||
Which of the following is NOT a valid HTTP method?
|
||||
|
||||
#### --distractors--
|
||||
|
||||
It returns the result of the promise.
|
||||
`PUT`
|
||||
|
||||
---
|
||||
|
||||
It stops the execution of subsequent promise handlers.
|
||||
`GET`
|
||||
|
||||
---
|
||||
|
||||
It retries the promise if it fails.
|
||||
`POST`
|
||||
|
||||
#### --answer--
|
||||
|
||||
It executes code after a promise is fulfilled or rejected, regardless of the outcome.
|
||||
`SEND`
|
||||
|
||||
### --question--
|
||||
|
||||
#### --text--
|
||||
|
||||
What is the syntax for declaring an async function?
|
||||
Which of the following is the correct syntax for creating an async function?
|
||||
|
||||
#### --distractors--
|
||||
|
||||
@@ -267,11 +283,11 @@ It creates a new promise.
|
||||
|
||||
---
|
||||
|
||||
It executes code immediately without waiting.
|
||||
It executes code immediately without waiting and returns an object.
|
||||
|
||||
---
|
||||
|
||||
It returns the result of the promise.
|
||||
It logs the result of the promise and returns `null`.
|
||||
|
||||
#### --answer--
|
||||
|
||||
@@ -281,85 +297,67 @@ It pauses the execution of the function until the promise is resolved.
|
||||
|
||||
#### --text--
|
||||
|
||||
What is the purpose of the Geolocation API?
|
||||
Which of the following APIs is used to provide a way for websites to request the user's location?
|
||||
|
||||
#### --distractors--
|
||||
|
||||
To manipulate HTML elements.
|
||||
Locator API
|
||||
|
||||
---
|
||||
|
||||
To create and manage map elements.
|
||||
Geo API
|
||||
|
||||
---
|
||||
|
||||
To control the device's camera.
|
||||
Locate API
|
||||
|
||||
#### --answer--
|
||||
|
||||
To retrieve the geographical location of a device.
|
||||
Geolocation API
|
||||
|
||||
### --question--
|
||||
|
||||
#### --text--
|
||||
|
||||
Which method of the Geolocation API is used to get the current position of the device?
|
||||
Which of the following attributes downloads the script asynchronously but waits for the HTML document to be fully parsed before running the script?
|
||||
|
||||
#### --distractors--
|
||||
|
||||
`getLocation()`
|
||||
`asyncDefer`
|
||||
|
||||
---
|
||||
|
||||
`getPosition()`
|
||||
`deferred`
|
||||
|
||||
---
|
||||
|
||||
`getLatLong()`
|
||||
`deferring`
|
||||
|
||||
#### --answer--
|
||||
|
||||
`getCurrentPosition()`
|
||||
`defer`
|
||||
|
||||
### --question--
|
||||
|
||||
#### --text--
|
||||
|
||||
What parameters can be passed to the `getCurrentPosition()` method?
|
||||
What will the following code return?
|
||||
|
||||
```js
|
||||
fetch('https://api.example.com/data')
|
||||
```
|
||||
|
||||
#### --distractors--
|
||||
|
||||
Only the success callback function.
|
||||
An error saying that the data is corrupted.
|
||||
|
||||
---
|
||||
|
||||
Only options.
|
||||
An error saying that the data cannot be fetched.
|
||||
|
||||
---
|
||||
|
||||
One the error callback function.
|
||||
|
||||
#### --answer--
|
||||
|
||||
Success and error callback functions, along with options.
|
||||
|
||||
### --question--
|
||||
|
||||
#### --text--
|
||||
|
||||
What will the following code return? `fetch('https://api.example.com/data')`
|
||||
|
||||
#### --distractors--
|
||||
|
||||
The JSON response directly.
|
||||
|
||||
---
|
||||
|
||||
An error if the URL is not reachable.
|
||||
|
||||
---
|
||||
|
||||
A synchronous response.
|
||||
Nothing will be returned and JavaScript will move to the next function in the script.
|
||||
|
||||
#### --answer--
|
||||
|
||||
@@ -391,65 +389,111 @@ What is the default HTTP method for the Fetch API?
|
||||
|
||||
#### --text--
|
||||
|
||||
What does the `Promise.all()` method do?
|
||||
Which of the following methods is used to delete resources on the server?
|
||||
|
||||
#### --distractors--
|
||||
|
||||
It resolves a single promise.
|
||||
`REMOVING`
|
||||
|
||||
---
|
||||
|
||||
It rejects the first promise that fails.
|
||||
`REMOVE`
|
||||
|
||||
---
|
||||
|
||||
It runs all promises sequentially.
|
||||
`DELETING`
|
||||
|
||||
#### --answer--
|
||||
|
||||
It executes multiple promises concurrently and returns the results when all are resolved.
|
||||
`DELETE`
|
||||
|
||||
### --question--
|
||||
|
||||
#### --text--
|
||||
|
||||
How do you handle multiple asynchronous operations using async/await?
|
||||
Which of the following is the correct way to create a promise?
|
||||
|
||||
#### --distractors--
|
||||
|
||||
You must always use `.then()` for each operation.
|
||||
```js
|
||||
const promise = get Promise((resolve, reject) => {
|
||||
setTimeout(() => {
|
||||
resolve('Data received successfully');
|
||||
}, 2000);
|
||||
});
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
You cannot handle multiple operations with async/await.
|
||||
```js
|
||||
const promise = set Promise((resolve, reject) => {
|
||||
setTimeout(() => {
|
||||
resolve('Data received successfully');
|
||||
}, 2000);
|
||||
});
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
You must use callback functions for all operations.
|
||||
```js
|
||||
const promise = put Promise((resolve, reject) => {
|
||||
setTimeout(() => {
|
||||
resolve('Data received successfully');
|
||||
}, 2000);
|
||||
});
|
||||
```
|
||||
|
||||
#### --answer--
|
||||
|
||||
You can use `await` for each operation in sequence and put them inside an async function.
|
||||
```js
|
||||
const promise = new Promise((resolve, reject) => {
|
||||
setTimeout(() => {
|
||||
resolve('Data received successfully');
|
||||
}, 2000);
|
||||
});
|
||||
```
|
||||
|
||||
### --question--
|
||||
|
||||
#### --text--
|
||||
|
||||
Which of the following is true about the `fetch` API?
|
||||
Which of the following attributes tells the browser to download the script file asynchronously while continuing to parse the HTML document?
|
||||
|
||||
#### --distractors--
|
||||
|
||||
It can only handle `GET` requests.
|
||||
`resolve`
|
||||
|
||||
---
|
||||
|
||||
It requires a callback function for handling responses.
|
||||
`catch`
|
||||
|
||||
---
|
||||
|
||||
It only works in synchronous code.
|
||||
`put`
|
||||
|
||||
#### --answer--
|
||||
|
||||
It is used to make HTTP requests to a server.
|
||||
`async`
|
||||
|
||||
### --question--
|
||||
|
||||
#### --text--
|
||||
|
||||
Which method of the Geolocation API is used to get the current position of a device?
|
||||
|
||||
#### --distractors--
|
||||
|
||||
`getLocation()`
|
||||
|
||||
---
|
||||
|
||||
`getPosition()`
|
||||
|
||||
---
|
||||
|
||||
`getLatLong()`
|
||||
|
||||
#### --answer--
|
||||
|
||||
`getCurrentPosition()`
|
||||
|
||||
|
||||
Reference in New Issue
Block a user