# JavaScript Quest: Pip and the Lighthouse

Beginner guide: solve(input) is called by the game. return supplies the answer. Checks compare outputs, not the syntax you chose.

## 1. Wake the beacon

Text values are strings. Put them inside quotes. return sends a value back from a function. The function wrapper is ready for you: edit the line inside it.

Mission: Return the exact string "Hello, Pip!".

```javascript
function solve(input) {
  return "Hello, Pip!";
}
```

## 2. Charge the battery

Numbers do not need quotes. + adds two numbers. input holds the value supplied by the game, so your code can work with different values.

Mission: Return input plus 2.

```javascript
function solve(input) {
  return input + 2;
}
```

## 3. Pack spare cells

const gives a value a name. A constant cannot be reassigned. * multiplies numbers. A helpful variable name explains what a number means.

Mission: Create a total worth input times 3, then return it.

```javascript
function solve(input) {
  const total = input * 3;
  return total;
}
```

## 4. Print a name badge

+ also joins strings. A space inside quotes is part of the text. input is a string in this mission.

Mission: Return "Hi, " followed by input.

```javascript
function solve(input) {
  return "Hi, " + input;
}
```

## 5. Open the energy gate

Comparisons return booleans: true or false. >= means greater than or equal to. Booleans are values, not the strings "true" or "false".

Mission: Return whether input is at least 5.

```javascript
function solve(input) {
  return input >= 5;
}
```

## 6. Choose a safe route

if runs a block when its condition is true. return exits the function, so a fallback return after the block handles the other case.

Mission: Return "go" when input is at least 5, otherwise "charge".

```javascript
function solve(input) {
  if (input >= 5) {
    return "go";
  }
  return "charge";
}
```

## 7. Check the secret word

=== checks equality without converting types. JavaScript strings are case-sensitive: "Pip" and "pip" are different.

Mission: Return whether input is exactly "spark".

```javascript
function solve(input) {
  return input === "spark";
}
```

## 8. Count your supplies

An array is an ordered list written with square brackets. Its length property tells you how many items it contains. An empty array has length zero.

Mission: Return the number of items in input.

```javascript
function solve(input) {
  return input.length;
}
```

## 9. Find the first tool

Array positions start at zero. input[0] reads the first item. Check the length before reading if you need a specific empty-case result.

Mission: Return the first item, or "empty" when there are no items.

```javascript
function solve(input) {
  if (input.length === 0) return "empty";
  return input[0];
}
```

## 10. Read the robot card

Objects group named properties inside braces. Dot notation reads a property: robot.name. Property names are case-sensitive.

Mission: Return input.name.

```javascript
function solve(input) {
  return input.name;
}
```

## 11. Gather the crystals

let allows a variable to change. A for...of loop visits each array value. Start a sum at zero so an empty list still has a useful result.

Mission: Return the sum of the numbers in input.

```javascript
function solve(input) {
  let total = 0;
  for (const energy of input) {
    total = total + energy;
  }
  return total;
}
```

## 12. Repair the signal

map makes a new array from the value returned for each item. n => n * 2 is a short function: receive n, return n times two.

Mission: Return a new array with every input number doubled.

```javascript
function solve(input) {
  return input.map(n => n * 2);
}
```

## 13. Keep working batteries

filter makes a new array containing items whose condition is true. Unlike map, it decides which values to keep instead of changing their values.

Mission: Return only numbers greater than zero.

```javascript
function solve(input) {
  return input.filter(n => n > 0);
}
```

## 14. Send a clean message

trim removes whitespace from the beginning and end of a string. toUpperCase changes letters to uppercase. Methods return values that you can pass to the next method.

Mission: Return input trimmed and uppercased.

```javascript
function solve(input) {
  return input.trim().toUpperCase();
}
```

## 15. Launch the lighthouse

A program often combines small ideas: read a value, repeat a step, compare a total, and return a decision. Use the skills from the island to solve this final mission.

Mission: Add all energy values in input. Return "launch" if the total is at least 10; otherwise return "recharge".

```javascript
function solve(input) {
  let total = 0;
  for (const energy of input) {
    total += energy;
  }
  return total >= 10 ? "launch" : "recharge";
}
```