我目前正在读Steven Foote的“学习编程”一书。这本书目前正在讨论自动化,并详细介绍了如何使用grunt。
我刚刚成功使用npm install -g grunt-cli
安装了grunt,但我现在遇到了一个我不熟悉的错误。
当我运行grunt时,我收到以下错误:
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>';
我对咕噜很新,所以我不知道如何解决错误。任何帮助将不胜感激。
答案 0 :(得分:1)
prompt.js
中只有一些错误的分配。在一些地方,您使用=
而不是+
来连接字符串。
替换为以下内容:
var userName = prompt('Hello what\'s your name?');
document.body.innerHTML = '<h1>Hello, ' + userName + '!</h1>' +
'<p>' + projectName + ' ' + versionNumber +
'accessed on: ' + currentTime + '</p>';