Syntax
`${x}`, [...x], { ...x }, => ({ }), and more — 10 exercises
Exercise 1 / 10
0 solved
Exercise 1/ 10
`…${x}…`
RuleInside text wrapped in ` ` (backquotes), put a value in with ${ }. You can write as many ${ } as you like in one text
Data(user・cart・bag・scarf)
const user = { name: "Emma", address: "Seattle", email: "emma@example.com" } const cart = [ { id: 1, name: "T-shirt", price: 2000, qty: 1, soldOut: false }, { id: 2, name: "Socks", price: 500, qty: 3, soldOut: false }, { id: 3, name: "Cap", price: 3000, qty: 1, soldOut: true }, ] // Items to add to the cart next const bag = { id: 4, name: "Bag", price: 4000, qty: 1, soldOut: false } const scarf = { id: 5, name: "Scarf", price: 2500, qty: 1, soldOut: false }
Example
// Text with the name and the address `${user.name} (${user.address})`
→ "Emma (Seattle)"The text "Emma's cart (3 items)" (take the name and the number of items from the data)
In plain words:Make text in ` ` with the buyer's name (user.name) and the number of items in the cart (cart.length) put in with ${ }
Expected result
"Emma's cart (3 items)"JavaScript
Solve it to continue