Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JSLint was unable to finish. 16.4Expected an identifier and instead saw '}'

Line 16.4, I keep getting this error stating the following: Expected an identifier and instead How do I fix this? Any help would be much appreciated. Thanks.

var ctx = document.getElementById("myChart").getContext("2d");
var myChart = new Chart(ctx, {
  type: "polarArea",
  data: {
    labels: ["HTML", "JQUERY", "JAVASCRIPT", "PYTHON", "CSS", "RUBY", "API"],
    datasets: [{
      backgroundColor: [
        "#adddcf",
        "#3498db",
        "#e8e7e5",
        "#bfb1d5",
        "#f0e0a2",
        "#fed1be",
        "#777777"
      ],
      data: [93, 67, 80, 73, 87, 38, 65],
    }]
  }
});


new Chart(ctx, {
    data: data,
    type: "polarArea",
    options: options
});
like image 894
KenjaminButton Avatar asked Dec 10 '25 01:12

KenjaminButton


1 Answers

"Other suggestions" are probably limited to "complete JSLinting the file". ;^) First, read up on JSLint directives to figure out how to keep some of the stuff that it's complaining about.

It's not that difficult for this file, thankfully.

  • If you're using document, you have to let JSLint know that it's working in a browser with browser:true.
  • If you're not following "JSLint accepted" whitespace, you need white:true for "messy whitespace".
  • You also need to let it know that some things are defined "out of scope", or it'll ask why, in this case, Chart is never defined. The global directive tells JSLint that Chart is defined somewhere else, is in your global scope already, and is fine to use here.
  • data and options in your new Chart call have to come from somewhere, so it's going to yell about that, obviously.

In the end, this lints...

/*jslint browser:true, white:true */
/*global Chart */

var ctx = document.getElementById("myChart").getContext("2d");
var myChart = new Chart(ctx, {
  type: "polarArea",
  data: {
    labels: ["HTML", "JQUERY", "JAVASCRIPT", "PYTHON", "CSS", "RUBY", "API"],
    datasets: [{
      backgroundColor: [
        "#adddcf",
        "#3498db",
        "#e8e7e5",
        "#bfb1d5",
        "#f0e0a2",
        "#fed1be",
        "#777777"
      ],
      data: [93, 67, 80, 73, 87, 38, 65]
    }]
  }
});


var data = "something";
var options = "something else";

new Chart(ctx, {
    data: data,
    type: "polarArea",
    options: options
});
like image 196
ruffin Avatar answered Dec 11 '25 21:12

ruffin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!