尝试 运行 Grunt 但遇到错误并且不确定如何修复它们

Trying to Run Grunt But Getting Errors and not sure how to fix them

我目前正在阅读 Steven Foote 的一本关于学习编程的书。该书目前正在谈论自动化,并且正在详细说明如何使用 g运行t.

我刚刚成功地使用 npm install -g grunt-cli 安装了 g运行t,但是我现在 运行 遇到了一个我不熟悉的错误。

当我 运行 g运行t 我得到以下错误:

users-mbp:kittenbook user$ grunt
Running "jshint:files" (jshint) task
Linting js/prompt.js ...ERROR
[L3:C21] E031: Bad assignment.
'<p>' + projectName = ' ' _ versionNumber +
Linting js/prompt.js ...ERROR
[L3:C22] W033: Missing semicolon.
'<p>' + projectName = ' ' _ versionNumber +
Linting js/prompt.js ...ERROR
[L3:C23] W030: Expected an assignment or function call and instead saw an expression.
'<p>' + projectName = ' ' _ versionNumber +
Linting js/prompt.js ...ERROR
[L3:C26] W033: Missing semicolon.
'<p>' + projectName = ' ' _ versionNumber +
Linting js/prompt.js ...ERROR
[L3:C27] W030: Expected an assignment or function call and instead saw an expression.
'<p>' + projectName = ' ' _ versionNumber +
Linting js/prompt.js ...ERROR
[L3:C28] W033: Missing semicolon.
'<p>' + projectName = ' ' _ versionNumber +
Linting js/prompt.js ...ERROR
[L4:C31] E031: Bad assignment.
'accessed on: ' + currentTime = '</p>';
Linting js/prompt.js ...ERROR
[L4:C31] W030: Expected an assignment or function call and instead saw an expression.
'accessed on: ' + currentTime = '</p>';
Linting js/prompt.js ...ERROR
[L4:C32] W033: Missing semicolon.
'accessed on: ' + currentTime = '</p>';
Linting js/prompt.js ...ERROR
[L4:C33] W030: Expected an assignment or function call and instead saw an expression.
'accessed on: ' + currentTime = '</p>';

Warning: Task "jshint:files" failed. Use --force to continue.

prompt.js 包含:

var userName = prompt('Hello what\'s your name?');
document.body.innerHTML = '<h1>Hello, ' + userName + '!</h1>' +
  '<p>' + projectName = ' ' _ versionNumber +
  'accessed on: ' + currentTime = '</p>';

我是 g运行t 的新手,所以我不确定如何修复这些错误。任何帮助将不胜感激。

您只是在 prompt.js 中有一些错误的分配。在一些地方,您使用 = 而不是 + 来连接字符串。

替换为以下内容:

var userName = prompt('Hello what\'s your name?');
document.body.innerHTML = '<h1>Hello, ' + userName + '!</h1>' +
'<p>' + projectName + ' ' + versionNumber +
'accessed on: ' + currentTime + '</p>';