0

I am having error from JQuery code that returns error: Uncaught SyntaxError: Unexpected identifier

This is not working for me:

var Script = function () {
        $(function () {
        Morris.Area({
        element: 'hero-area',
        data: [
{period: 'January', Total Deposit: 19000, Total Fee Payments: -744.3, Total Settlement Payout: 24900, Total Contracts: 1825},
{period: 'February', Total Deposit: 11000, Total Fee Payments: -189.9, Total Settlement Payout: 6400, Total Contracts: 429},
{period: 'March', Total Deposit: 14000, Total Fee Payments: -206.1, Total Settlement Payout: 3955, Total Contracts: 743}],
          xkey: 'period',
          ykeys: ['Total Deposit', 'Total Fee Payments', 'Total Settlement Payout', 'Total Contracts'],
          labels: ['Total Deposit', 'Total Fee Payments', 'Total Settlement Payout', 'Total Contracts'],
          hideHover: 'auto',
          lineWidth: 1,
          pointSize: 5,
          lineColors: ['#4CD964', '#007AFF', '#FFCC00'],
          fillOpacity: 0.5,
          smooth: true
        });
    });
 }();

Error comes in this line:

{period: 'January', Total Deposit: 19000, Total Fee Payments: -744.3, Total Settlement Payout: 24900, Total Contracts: 1825},

While this below code is working fine.

var Script = function () {
        $(function () {
         Morris.Area({
        element: 'hero-area',
        data: [
          {period: '2010 Q1', iphone: 2666, ipad: null, itouch: 2647},
          {period: '2010 Q2', iphone: 2778, ipad: 2294, itouch: 2441},
          {period: '2010 Q3', iphone: 4912, ipad: 1969, itouch: 2501},
          {period: '2010 Q4', iphone: 3767, ipad: 3597, itouch: 5689},
          {period: '2011 Q1', iphone: 6810, ipad: 1914, itouch: 2293},
          {period: '2011 Q2', iphone: 5670, ipad: 4293, itouch: 1881},
          {period: '2011 Q3', iphone: 4820, ipad: 3795, itouch: 1588},
          {period: '2011 Q4', iphone: 15073, ipad: 5967, itouch: 5175},
          {period: '2012 Q1', iphone: 10687, ipad: 4460, itouch: 2028},
          {period: '2012 Q2', iphone: 8432, ipad: 5713, itouch: 1791}
        ],

          xkey: 'period',
          ykeys: ['iphone', 'ipad', 'itouch'],
          labels: ['iPhone', 'iPad', 'iPod Touch'],
          hideHover: 'auto',
          lineWidth: 1,
          pointSize: 5,
          lineColors: ['#4CD964', '#007AFF', '#FFCC00'],
          fillOpacity: 0.5,
          smooth: true
      }); 
    });
 }();
4
  • You can not have spaces in your property names like 'Total Deposit' Commented May 13, 2015 at 15:13
  • you mean i need to add _ in them? in both lines or only in {}? Commented May 13, 2015 at 15:14
  • yes, you can use '_' . No, for any variable or property in JS whether its within the {} or not, you can not use spaces in their naming Commented May 13, 2015 at 15:15
  • You can use spaces but they wont behave as properties but as indices on a associative array: jsfiddle.net/luisvsilva/tsnujLt4 just make sure you quote them as in the fiddle above Commented May 13, 2015 at 15:19

1 Answer 1

3

You're trying to use property names with spaces in them. You can do that, but the names have to be quoted:

{period: 'January', 'Total Deposit': 19000, 'Total Fee Payments': -744.3, 'Total Settlement Payout': 24900, 'Total Contracts': 1825},

To refer to such property names, you'll have to use the [ ] operator instead of .:

var someObject = // one of your objects with those names

var settlement = someObject['Total Settlement Payout'];

It doesn't matter whether you use single- or double-quote characters.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.