AppLab error e.replace is not a function when reading from data set

188 views Asked by At
function Checkout(Payment_Type, Tip_Amt){
    var Cust_Order = [];
    readRecords(Order_Data,{},function(Rec){
        for (var i = 0; i < Rec.length; i++) {
            appendItem(Cust_Order, Rec[i].Table);
            appendItem(Cust_Order, Rec[i].Type);
            appendItem(Cust_Order, Rec[i].Item);
            appendItem(Cust_Order, Rec[i].Price);
    }
    console.log(Cust_Order);
  });
}

This is part of a restaurant ordering app I have to build for uni. I've saved the customers order in a data set and now I wish to read from that dataset and get the order to be able to calculate the bill and produce an itemised bill

WARNING: Line: 176: readRecords() table parameter value ([object Object]) is not a string.ERROR: Line: 176: TypeError: e.replace is not a function. (In 'e.replace(m,"-")', 'e.replace' is undefined)

1

There are 1 answers

0
wutadam On

Well, for one, your code is really botched. The table name in readRecords isn't a string, and you don't actually need to loop through every entry in the bill to get everything. The returned records are formatted as an object.

function Checkout(Payment_Type, Tip_Amt){
    var Cust_Order = [];
    readRecords("Order_Data",{},function(Rec){
        // Use Rec to get the bill after this line.
        console.log(Rec);
    }
  });
}

From there, you could effectively give them an itemized bill. Just make sure that you clear the table each time you get a new customer.