So I’m taking the training wheels off and will be working in an editor (Brackets), instead of codepen. I started a draft of a project in codepen but I’m having some trouble moving it over and making sure the javascript still works.
My html head section; my css seems to link fine but no dice with the js:
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.min.js"></script>
<link rel="stylesheet" type="text/css" href="style.css">
<link href="http://netdna.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap.min.css"
rel="stylesheet">
<script src="javascript.js"></script>
</head>
My JS file:
$(document).ready(function() {
var backgrounds = [
// 'url("https://i.imgsafe.org/fcad878b58.jpg")',
'url("https://i.imgsafe.org/fd8d13a4dd.jpg")',
'url("https://i.imgsafe.org/fd92240bdb.jpg")',
'url("https://i.imgsafe.org/8c6fd20f8b.jpg")',
];
var i = 0;
setInterval(function() {
$("#pageContainer").css("background-image", backgrounds[i]);
i++
if (i > backgrounds.length) {
i = 0;
}
}, 4000);
});
Am I doing something wrong in the way I’m loading the js file or adding the jQuery library? My editor is also giving me a number of errors about my js code which I wasn’t getting with codepen:
1 '$' was used before it was defined. $(document).ready(function() {
1 Expected exactly one space between 'function' and '('. $(document).ready(function() {
3 Missing 'use strict' statement. var backgrounds = [
3 Expected 'var' at column 5, not column 3. var backgrounds = [
5 Expected 'url("https://i.imgsafe.org/fd8d13a4dd.jpg")' at column 13, not column 5. 'url("https://i.imgsafe.org/fd8d13a4dd.jpg")',
6 Expected 'url("https://i.imgsafe.org/fd92240bdb.jpg")' at column 13, not column 5. 'url("https://i.imgsafe.org/fd92240bdb.jpg")',
7 Expected 'url("https://i.imgsafe.org/8c6fd20f8b.jpg")' at column 13, not column 5. 'url("https://i.imgsafe.org/8c6fd20f8b.jpg")',
7 Unexpected ','. 'url("https://i.imgsafe.org/8c6fd20f8b.jpg")',
18 Expected ']' at column 9, not column 3. ];
19 Expected 'var' at column 5, not column 3. var i = 0;
19 Combine this with the previous 'var' statement. var i = 0;
20 Expected 'setInterval' at column 5, not column 3. setInterval(function() {
20 Expected exactly one space between 'function' and '('. setInterval(function() {
22 Expected '$' at column 9, not column 5. $("#pageContainer").css("background-image", backgrounds[i]);
23 Expected 'i' at column 9, not column 5. i++
23 Unexpected '++'. i++
23 Expected ';' and instead saw 'if'. i++
24 Expected 'if' at column 9, not column 5. if (i > backgrounds.length) {
25 Expected 'i' at column 13, not column 7. i = 0;
26 Expected '}' at column 9, not column 5. }
27 Expected '}' at column 5, not column 3. }, 4000);
Not really sure where these came from. Any help would be greatly appreciated.