 # Money Changer explainer

#1

The aim of this puzzle: Use the `inYen` function to convert US dollars into Japanese yen.

Walkthrough of the solution: The starter code has the `inYen()` function already completed for you. If you give it a number (of dollars) in its parentheses (like putting a number in `pickRandom()`) it will give back how many Japanese yen it’s worth.

The lines of code at the bottom print out the number that’s going to be converted, and then runs the `inYen()` function using that number.

The last line of the starter code prints out “100 US dollars is:”. To convert 100 dollars into yen, you use `inYen(100)`. That will calculate the correct number, but you won’t see the value on the screen unless you put it inside `console.log()`. This command should go at the very bottom of your code.

Sample code solution:
(Tap below to reveal)

``````function inYen(dollars) {
let amount = dollars * 113;
return amount;
}

console.log('20 US dollars is:');
console.log(inYen(20) + ' Japanese yen');
console.log('100 US dollars is:');
console.log(inYen(100) + ' Japanese yen');

``````

JavaScript Concepts: Arithmetic Operators (*), Binary Expression (+ concatenation), Calling Functions, Code Block (function), `console.log()`, Variable Scope (let)

#3

Is it possible to see the starter code in every level? How is inyen connected to amount?

#4

There is no hidden code in this puzzle like some of the earlier ones. When I say “starter code”, I mean the code that is visible on the screen when you first start the puzzle, or reset it.

When you call the `inYen()` function, it will create its own `amount` variable which gets a starting value equal to `dollars * 113`. `dollars` is called a parameter, it’s a placeholder variable that gets a value only when you call the `inYen()` function.

For example, `inYen(20)` means, “run the `inYen` function and use `20` as the input value”. That will store `20` inside of `dollars`. Then, `amount` gets created and has a value of `dollars * 113` which is equal to `20 * 113` for this specific time running the function. `20 * 113` is `2260`, so that is the final value for `amount`. Then the `amount` (`2260`) gets “returned” which means that’s the final output of the function call. We started out with the code `inYen(20)`, and in the end, we can simply substitute that with the number `2260`.

–Frankie