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)