0
0
Javascriptprogramming~20 mins

Output formatting basics in Javascript - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Output Formatting Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2: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}`);
AName: name, Age: age
BName: ${name}, Age: ${age}
CName: Alice Age: 30
DName: Alice, Age: 30
Attempts:
2 left
💡 Hint
Remember that template literals use backticks and ${} to insert variables.
Predict Output
intermediate
2: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)}`);
APrice: $5
BPrice: $5.00
CPrice: $5.0
DPrice: $5.000
Attempts:
2 left
💡 Hint
toFixed(2) formats the number with exactly two decimal places.
Predict Output
advanced
2: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'));
A00042
B42
C42000
D43
Attempts:
2 left
💡 Hint
padStart adds characters to the start until the string reaches the given length.
Predict Output
advanced
2: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));
AUSD 1,234.56
B1234.56 USD
C$1,234.56
D1,234.56
Attempts:
2 left
💡 Hint
Intl.NumberFormat formats numbers according to locale and options.
🧠 Conceptual
expert
2:00remaining
Which option causes a runtime error when formatting output?
Which of the following code snippets will cause a runtime error when executed?
Aconsole.log(`Result: ${undefinedVariable}`);
Bconsole.log('Value: ' + (10).toFixed(2));
Cconsole.log(`Sum: ${5 + 3}`);
Dconsole.log('Price: $' + (20).toLocaleString('en-US'));
Attempts:
2 left
💡 Hint
Check if all variables are defined before using them in output.