Question: ```
var tipsArray = [];
var finalBillArray = [];
var tip;
var finalBill;

function calculator(bill) {
    finalBill = tip + bill;

    if (bill < 50) {
        tip = bill * 0.2;
    } else if (bill >= 50 && bill <= 200) {
        tip = bill * 0.15;
    } else {
        tip = bill * 0.1;
    }

    tipsArray.push(tip);
    finalBillArray.push(finalBill);

    }

calculator(124);
calculator(48);
calculator(268);

console.log(tipsArray);
console.log(finalBillArray);

```

I'm trying to solve one of the tasks on UDEMY course. And can't understand, why only first element in finalBillArray is NaN, but the others looks good.

Answer: 
In your current code, `tip` is not assigned to until the `if (bill...` tests inside `calculator`, *below* the assignment to `finalBill`. Assign to `finalBill` *after* creating the `tip` instead, which will not only result in no `NaN`s, but will also give you *accurate* results (your current tips for each bill are being calculated based on the tip of the *previous* bill, not the current bill):

```js
var tipsArray = [];
var finalBillArray = [];

function calculator(bill) {

  var tip;
  var finalBill;
  if (bill < 50) {
    tip = bill * 0.2;
  } else if (bill >= 50 && bill <= 200) {
    tip = bill * 0.15;
  } else {
    tip = bill * 0.1;
  }

  tipsArray.push(tip);
  finalBill = tip + bill;
  finalBillArray.push(finalBill);

}

calculator(124);
calculator(48);
calculator(268);

console.log(tipsArray);
console.log(finalBillArray);
```

If you don't like the floating-point numbers there, you can use `Math.round` as well; `Math.round(tip * 100) / 100;` will round to 2 decimal places. (If you don't need a number, you can use `toFixed(2)` instead, which is easier)

```js
var tipsArray = [];
var finalBillArray = [];

function calculator(bill) {

  var tip;
  var finalBill;
  if (bill < 50) {
    tip = bill * 0.2;
  } else if (bill >= 50 && bill <= 200) {
    tip = bill * 0.15;
  } else {
    tip = bill * 0.1;
  }
  tip = Math.round(tip * 100) / 100;

  tipsArray.push(tip);
  finalBill = tip + bill;
  finalBillArray.push(finalBill);

}

calculator(124);
calculator(48);
calculator(268);

console.log(tipsArray);
console.log(finalBillArray);
```
Tip should be used only after it calculated / initialize .

```
finalBill = tip + bill;

```

You're using tip without initializing it , therefore - `NUM + NAN = NAN`

```
function calculator(bill) {
    if (bill < 50) {
        tip = bill * 0.2;
    } else if (bill >= 50 && bill <= 200) {
        tip = bill * 0.15;
    } else {
       tip = bill * 0.1;
    }
    finalBill = tip + bill;
    tipsArray.push(tip);
    finalBillArray.push(finalBill);

    }

```