JS
…

Module 7 of 10

functions

Declare functions, pass arguments, return values, and use defaults.

JavaScript Basics · 0/12 completed · scroll down for every challenge

Challenge 1 of 12

Double it

Instructions

Write function `double` that returns n * 2.

Editor

IntelliSense on

// Write your code below

Challenge 2 of 12 · Add two numbers

Challenge 2 of 12

Add two numbers

Instructions

Write function `add` that returns the sum of `a` and `b`.

Editor

IntelliSense on

// Write your code below

Challenge 3 of 12 · Default parameter

Challenge 3 of 12

Default parameter

Instructions

Write `greet(name = "friend")` that returns `Hello, ${name}!`.

Editor

IntelliSense on

// Write your code below

Challenge 4 of 12 · Arrow function

Challenge 4 of 12

Arrow function

Instructions

Create `square` as an arrow function that returns n * n.

Editor

IntelliSense on

// Write your code below

Challenge 5 of 12 · Even check

Challenge 5 of 12

Even check

Instructions

Write `isEven(n)` that returns true when n is divisible by 2.

Editor

IntelliSense on

// Write your code below

Challenge 6 of 12 · Max of two

Challenge 6 of 12

Max of two

Instructions

Write `max(a, b)` that returns the larger number.

Editor

IntelliSense on

// Write your code below

Challenge 7 of 12 · Min of two

Challenge 7 of 12

Min of two

Instructions

Write `min(a, b)` that returns the smaller number.

Editor

IntelliSense on

// Write your code below

Challenge 8 of 12 · Return early

Challenge 8 of 12

Return early

Instructions

Write `label(n)` — return `"zero"` if n is 0, otherwise return n.

Editor

IntelliSense on

// Write your code below

Challenge 9 of 12 · Rest parameters

Challenge 9 of 12

Rest parameters

Instructions

Write `sumAll(...nums)` that returns the sum of all arguments.

Editor

IntelliSense on

// Write your code below

Challenge 10 of 12 · Absolute value

Challenge 10 of 12

Absolute value

Instructions

Write `abs(n)` that returns n if n >= 0, otherwise -n. Do not use Math.abs.

Editor

IntelliSense on

// Write your code below

Challenge 11 of 12 · Full name helper

Challenge 11 of 12

Full name helper

Instructions

Write `fullName(first, last)` that returns `"first last"`.

Editor

IntelliSense on

// Write your code below

Challenge 12 of 12 · Is empty string

Challenge 12 of 12

Is empty string

Instructions

Write `isEmpty(text)` that returns true when the string length is 0.

Editor

IntelliSense on

// Write your code below

Next module