我是 javascript 新手,正在尝试通过 JSLint 进行验证。我应该在哪里放置“使用严格”以在全球范围内使用它并进行验证?
这给了我错误“语句位置出现意外的表达式'use strict'。”:
"use strict";
console.log('doing js in head-section');
function helloWorld() {
console.log('called function helloWorld()');
alert('Hello World from a JS function showing an alert!');
}
function helloMyNumber() {
console.log('called function helloMyNumber()');
var max = 42;
var yourLuckyNumber = prompt('Enter your lucky number (between 1 and '+ max +')');
var myLuckyNumber = Math.floor(Math.random()*(max+1));
var paragraph = document.getElementById('luckynumber');
paragraph.innerHTML = paragraph.innerHTML + ' Your lucky number is: ' + yourLuckyNumber + '. Mine is: ' + myLuckyNumber + '. They ' + (yourLuckyNumber == myLuckyNumber ? 'DID ' : 'did NOT ') + 'match!';
}
console.log('doing JS in body-section');
document.writeln('<p class="green">Hello World from JS within a body-section in HTML!</p>');