Can someone explain the parameter example from YDKJS? I don't get how It knows that amt = amount

How does it know that amt = amount? Is this a built in abbreviation? If so, is there a list of the for future reference?

function printAmount(amt) {
    console.log( amt.toFixed( 2 ) );
}

function formatAmount() {
    return "$" + amount.toFixed( 2 );
}

var amount = 99.99;

printAmount( amount * 2 );      // "199.98"

amount = formatAmount();
console.log( amount );          // "$99.99"

In this example you have two different functions.

This one receives a parameter, in this case called amt, but you could call it anything. And inside it uses this variable amt.

function printAmount(amt) {
   console.log( amt.toFixed( 2 ) );
}

In this one, you are not receiving a parameter, but using the amount variable you declared outside the function. If you change amount.toFixed(2) to amt.toFixed(2) it would not work. Also, note how this function does not have a parameter.

function formatAmount() {
   return "$" + amount.toFixed( 2 );
}

So, it is not a built-in abbreviation, but it is the name of the parameter you set in the function.

I cleaned up your code.
You need to use triple backticks to post code to the forum.
See this post for details.

1 Like

Look again at how to build functions.

You would be doing yourself a huge favor if you took a break from FCC, and JavaScript in general to do some of this:

It’s Udacity’s most popular course (it’s free), and for pretty good reason. It’ll teach you what you need to know in a more entertaining format, and you’ll still be writing code a lot more than you are with YDKJS. It’s in Python which is even easier than Javacript. Chapters 1 - 3 are all you really need.

So amt is a variable, but it just doesn’t show the variable?

No, amt is an argument.