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: 
Your problem is that your `tip` variable is not initialized when you call the function in other words it's `undefined`, so when you call :

```
finalBill = tip + bill;

```

It will return `NaN` because, `undefined+bill` is not a valid `Number`.

**Solution:**

You just need to put the line `finalBill = tip + bill;` after your `if` block, so the `tip` variable can be correctly be initialized.

```
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;

```

**Demo:**

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

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);

    }

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);

    }

```