[英]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.