Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to print 'Hello, world!' to the console.
Javascript
console.[1]('Hello, world!');
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using console.print or console.write which do not exist in JavaScript.
Trying to use echo which is from other languages.
✗ Incorrect
The console.log method prints messages to the console in JavaScript.
2fill in blank
mediumComplete the code to create a new Promise that resolves with 'Done'.
Javascript
const promise = new Promise((resolve, reject) => { resolve([1]); }); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Passing Error to resolve instead of reject.
Using null or false which are not the intended resolved value.
✗ Incorrect
The Promise resolves with the string 'Done' using resolve('Done').
3fill in blank
hardFix the error in the async function to await the promise correctly.
Javascript
async function fetchData() { const result = [1] promise; return result; } Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using promise.then() without await inside async function.
Trying to use resolve or async keywords incorrectly.
✗ Incorrect
The await keyword pauses the async function until the promise resolves.
4fill in blank
hardFill both blanks to create a setTimeout that logs 'Hi' after 1 second.
Javascript
setTimeout(() => { console.[1]('Hi'); }, [2]); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using console.error instead of console.log.
Using 500 instead of 1000 for delay.
✗ Incorrect
console.log prints the message, and 1000 means 1000 milliseconds (1 second) delay.
5fill in blank
hardFill all three blanks to create a Promise that rejects with 'Fail' after 2 seconds.
Javascript
const failPromise = new Promise(([1], [2]) => { setTimeout(() => { [2]('[3]'); }, 2000); });
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping resolve and reject parameters.
Calling resolve instead of reject to indicate failure.
Using 'Success' instead of 'Fail' as rejection message.
✗ Incorrect
The Promise executor takes resolve and reject. We call reject('Fail') after 2 seconds to reject the promise.