TypeScript Coding Practice
Practice typing real code syntax, including brackets, punctuation, and indentation. Snippets are for typing practice only and are never executed.
Interfaces and array methods
Type the code exactly. Tab inserts four spaces. Code is not executed.
Progress: 0%
Current mismatches: 0
interface Product {
id: number;
name: string;
price: number;
}
const products: Product[] = [
{ id: 1, name: "Notebook", price: 4.5 },
{ id: 2, name: "Pen", price: 1.25 },
];
const total = products.reduce(
(sum, product) => sum + product.price,
0
);
console.log(`Total: $${total.toFixed(2)}`);
Type the code exactly, including spaces and indentation.