How to print the second digit of '0'

when the price is printed to the console?

Hello @paulgureghian. You could either use a float, and round to two decimals, using toFixed, or you could have some if…else checking, but I wouldn’t recommend that.
If you wanted to use toFixed, check this website out:
I hope this helps!

I’ll take a look and see if I can implement the ‘toFixed’ solution. thanks.

I tried: const totalPrice.toFixed(2) , but It didn’t work.

Keep in mind that .toFixed() will not modify the original value for the variable (in this case totalPrice). If you want to store it, you’ll have to use a new variable like
const totalPrice2digits = totalPrice.toFixed(2)

I’m assuming you defined your totalPrice as:
const totalPrice = appetizer.price + main.price + dessert.price;

Lets give it a try …

Think I’ll try: const totalPrice = totalPrice2digits.toFixed(2)

So I can keep using ‘totalPrice’ in the return statement.

That worked. thanks.

There are many ways to do it! Look at some examples:

// Example values
const appetizer = 4.1;
const main = 3;
const dessert = 5;
const totalPrice = appetizer + main + dessert;
console.log(`Your total is: ${totalPrice}`);

// You can make a new variable to have different formatting
const firstExampleTotalPrice = totalPrice.toFixed(2);

// Or you can modify the original variable, but it cannot be const
// You will need to define it with let so you can modify it
// (because const variables can't be modified after declared!)
let secondExampleTotalPrice = appetizer + main + dessert;
secondExampleTotalPrice = secondExampleTotalPrice.toFixed(2);

// Finally, you could wrap the definition of totalPrice with toFixed()
const thirdExampleTotalPrice = (appetizer + main + dessert).toFixed(2);

1 Like

The thing to also bear in mind about number.toFixed() is that the output is a string object, not a number.

Yup. got it, looks the way I want. thanks.