Challenge - 5 Problems
Output Formatting Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
What is the output of this template literal?
Consider the following JavaScript code using template literals. What will be printed to the console?
Javascript
const name = "Alice"; const age = 30; console.log(`Name: ${name}, Age: ${age}`);
Attempts:
2 left
💡 Hint
Remember that template literals use backticks and ${} to insert variables.
✗ Incorrect
Template literals allow embedding variables inside strings using ${variable}. The output replaces these placeholders with actual values.
❓ Predict Output
intermediate2:00remaining
What does this code print with number formatting?
Look at this code that formats a number to two decimal places. What is the output?
Javascript
const price = 5; console.log(`Price: $${price.toFixed(2)}`);
Attempts:
2 left
💡 Hint
toFixed(2) formats the number with exactly two decimal places.
✗ Incorrect
The toFixed(2) method converts the number to a string with two digits after the decimal point.
❓ Predict Output
advanced2:00remaining
What is the output of this code using padStart?
This code uses padStart to format a string. What will it print?
Javascript
const id = "42"; console.log(id.padStart(5, '0'));
Attempts:
2 left
💡 Hint
padStart adds characters to the start until the string reaches the given length.
✗ Incorrect
padStart(5, '0') adds zeros to the left of '42' until the total length is 5 characters.
❓ Predict Output
advanced2:00remaining
What is the output of this code using Intl.NumberFormat?
This code formats a number as currency. What will it print?
Javascript
const amount = 1234.56; const formatter = new Intl.NumberFormat('en-US', { style: 'currency', currency: 'USD' }); console.log(formatter.format(amount));
Attempts:
2 left
💡 Hint
Intl.NumberFormat formats numbers according to locale and options.
✗ Incorrect
The formatter formats the number as US dollars with commas and two decimals.
🧠 Conceptual
expert2:00remaining
Which option causes a runtime error when formatting output?
Which of the following code snippets will cause a runtime error when executed?
Attempts:
2 left
💡 Hint
Check if all variables are defined before using them in output.
✗ Incorrect
Using an undefined variable inside a template literal causes a ReferenceError at runtime.