I am new to the Web Development, so i am trying a to learn JavaScript, but i'm always getting this Error.
Code:
var myImage = document.querySelector('img');
myImage.onclick = function () {
var mySrc = myImage.getAttribute('src');
if (mySrc === 'images/old-big-garage.png') {
myImage.setAttribute('src', 'images/name1.png');
} else {
myImage.setAttribute('src', 'images/old-big-garage.png');
}
}
Errors:
JSLint (4)
4 Missing 'use strict' statement. var mySrc = myImage.getAttribute('src');
6 Expected 'myImage' at column 9, not column 7. myImage.setAttribute('src', 'images/papst.png');
8 Expected 'myImage' at column 9, not column 7. myImage.setAttribute('src', 'images/old-big-garage.png');
10 Expected ';' and instead saw '(end)'. }
ESLint (1)
1 ERROR: 'document' is not defined. [no-undef] var myImage = document.querySelector('img');