0
0
Javascriptprogramming~10 mins

JavaScript runtime overview - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to print 'Hello, world!' to the console.

Javascript
console.[1]('Hello, world!');
Drag options to blanks, or click blank then click option'
Alog
Bprint
Cwrite
Decho
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.
2fill in blank
medium

Complete 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'
AError
Bfalse
Cnull
D'Done'
Attempts:
3 left
💡 Hint
Common Mistakes
Passing Error to resolve instead of reject.
Using null or false which are not the intended resolved value.
3fill in blank
hard

Fix 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'
Apromise.then()
Bresolve
Cawait
Dasync
Attempts:
3 left
💡 Hint
Common Mistakes
Using promise.then() without await inside async function.
Trying to use resolve or async keywords incorrectly.
4fill in blank
hard

Fill 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'
Alog
B1000
C500
Derror
Attempts:
3 left
💡 Hint
Common Mistakes
Using console.error instead of console.log.
Using 500 instead of 1000 for delay.
5fill in blank
hard

Fill 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'
Aresolve
Breject
CFail
DSuccess
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.