简体   繁体   English

我收到许多错误,例如“预期在第 4 列而非第 2 列中使用严格的”。 这是什么意思?

[英]I'm getting many errors like "Expected 'use strict' at column 4, not column 2." What does this mean?

I'm assuming since it mentions columns that it's off based off of there being a difference in spaces of the open and closed tags.我假设因为它提到了基于开放和封闭标签的空间差异而关闭的列。 How do I fix these though?我该如何解决这些问题? It seems like the few I solve, the more pop up.好像我解决的越少,弹出的越多。 I've tried redoing my code since I started and it worked, however it was just missing the alert(...Popup) in my change() function and didn't have the variable tickbag.我从一开始就尝试重做我的代码并且它有效,但是它只是在我的 change() 函数中缺少 alert(...Popup) 并且没有变量 tickbag。 I'm just astounded that it could be fine and then just shatter with minimal code additions that "shouldn't" (according to what I know) have any affect on the program as a whole.我只是惊讶于它可能没问题,然后只是添加了“不应该”(根据我所知道的)对整个程序产生任何影响的最少代码添加。

Here is my code:这是我的代码:

// Travel Calculator JavaScript
// don't forget to validate at https://jslint.com

/*jslint devel: true, browser: true */

// self-executing "global" anonymous function
// it's here to keep variable and function scope
// contained within our script
(function () {

  // use strict enforces more rules
  // rules make us better programmers
  "use strict";

  // === === === === === === === === === === === === ===
  // === === === ===   global variables  === === === ===
  // === === === ===      begin here     === === === ===
  // === === === === === === === === === === === === ===



  var mileage = 100;
  var mpg = 20;
  var ppg = 2.50;
  var payrate = 15;
  var travelers = 2;
  var ticketprice = 250;
  var baggage = 25;
  var vehicletotal = 0;
  var persontotal = 0;
  var airtotal = 0;
  var vehicleperson = 0;
  var output = 0;
  var hotel = 300;
  var tickbag = 0;


  // this is how ouputting the console log works. will miss up code
  // if not here
  console.log("-- travel-calculator.js starting --");

  console.log("-----------------------------\n\n\n");

  // === === === === === === === === === === === === ===
  // === === === ===   global functions  === === === ===
  // === === === ===      begin here     === === === ===
  // === === === === === === === === === === === === ===

  function byID(element) {
    return document.getElementById(element);
  }

  function calculate() {

    // grab the current column1 column and save it!
    mileage = Number(byID("mileage").value);
    mpg = Number(byID("mpg").value);
    ppg = Number(byID("ppg").value);
    travelers = Number(byID("travelers").value);
    payrate = Number(byID("payrate").value);
    ticketprice = Number(byID("ticketprice").value);
    baggage = Number(byID("baggage").value);
    hotel = Number(byID("hotel").value);

    vehicletotal = (mileage / mpg * ppg);
    persontotal = (travelers * (8 * payrate));
    tickbag = (ticketprice + baggage);
    airtotal = (ticketprice + baggage) * travelers;
    vehicleperson = vehicletotal + persontotal + hotel;

    output = "Vehicle Costs: $" + (vehicletotal).toFixed(2) + "\n";
    output += "Traveler Costs: $" + persontotal.toFixed(2) + "\n";
    output += "Air Cost per Person: $" + tickbag.toFixed(2) + "\n";
    output += "Total Cost by Car: $" + vehicleperson.toFixed(2) + "\n";
    output += "Total Cost by Plane: $" + airtotal.toFixed(2) + "\n";


    alert(output);
  }

  function change() {
    var image = byID("testing");
    var carPopup = ("It is cheaper to take a car!");
    var airPopup = ("It is cheaper to take a plane!");

    if (vehicleperson < airtotal) {
      image.src = "images/green_mini_cooper.jpg";
      alert(carPopup);
    } else {
      image.src = "images/airplane.jpg";
      alert(airPopup);
    }
  }

  console.log("-- updated by click --");

  console.log("----------------------\n\n\n");

  console.log("-- updated by \"calculate\" --");

  console.log("-------------------------\n\n\n");

  byID("calculate-button").addEventListener("click", calculate);
  byID("calculate-button").addEventListener("click", change);

}());

jslint wants your indentation to be in sets of 4 spaces rather than 2. jslint 希望你的缩进是 4 个空格而不是 2 个。

If you want to continue to indent by 2 spaces generally, you can add white: true to the jslint comment at the top of your file.如果您想继续缩进 2 个空格,您可以在文件顶部的jslint注释中添加white: true This will ignore the whitespace warnings.这将忽略空白警告。

Change: /*jslint devel: true, browser: true */更改: /*jslint devel: true, browser: true */

to: /*jslint devel: true, browser: true, white: true */ to: /*jslint devel: true, browser: true, white: true */

You can get help from the jslint site (Look for the section on whitespace): https://www.jslint.com/help.html您可以从 jslint 站点获得帮助(查找有关空白的部分): https : //www.jslint.com/help.html

And test your code if you like: https://www.jslint.com/如果您愿意,还可以测试您的代码: https : //www.jslint.com/

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 错误“htmlfile:invalid argument”是什么意思? 我在excanvas.js中得到这个 - What does the error “htmlfile: invalid argument” mean? I'm getting this in excanvas.js 我的拖放 function 不起作用。 我收到一个类型错误。 这是什么意思? - My drag and drop function isn't working. I'm getting a TypeError. What does this mean? t / = d是什么意思? Python并获得错误 - What does t /= d mean? Python and getting errors 在javascript中使用this关键字时,如果遭到严格的违反,这是什么意思? - What does it mean when I get a strict violation when using the this keyword in javascript? AngularJS收到“缺少&#39;使用严格的&#39;声明”错误,甚至更艰难,我已经包含了这些声明 - AngularJS getting “Missing 'use strict' statement”-errors, even tough I've included the statements 为什么 Postgres 谈论第 0 列; 这是什么意思? - Why is Postgres talking about column 0; and what does it mean? 在 Chrome 开发工具的启动器列中:-infinity 是什么意思 - What does :-infinity mean in Initiator column of Chrome dev tools 我正在尝试使用一个jQuery,但出现两个错误: - I'm trying to use a jquery but getting two errors: 我怎样才能使用 Route 而不会出现这样的错误 - how can i use Route without getting any errors like this SyntaxError:预期的表达式,得到&#39;&lt;&#39;,那是什么意思? - SyntaxError: expected expression, got '<', what does that mean?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM