Overview
Write compact arrow functions with default parameters by building the HTML tags a page is made of.
- (a, b) => a + b returns the expression
- With { } braces you need return
- Default parameters like tag = "p"
Short Course
An arrow function without braces returns its expression. A default
parameter fills in a missing argument. The trap: once you add { }, nothing
is returned unless you write return.
const double = n => n * 2;
double(4); // 8
const broken = n => { n * 2 };
broken(4); // undefined
const greet = (name = "you") => `Hi ${name}`;
greet(); // "Hi you"
Task
Write the arrow function makeTag(text, tag) where tag defaults to "p",
e.g. makeTag("Hello") returns <p>Hello</p> and makeTag("Welcome", "h1")
returns <h1>Welcome</h1>.
Test Suites
Pending
Next
Output