JavaScript code doesn't work in chrome. I gives me an error:
VM180:1 Uncaught SyntaxError: Invalid or unexpected token
When I see on console in chrome, all my code is written in Chinese, but in my code file, it is written in English.
HTML
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" type="text/css" href="jqs.css">
</head>
<body>
<ul id="slides">
<li class="slide showing">Slide 1</li>
<li class="slide">Slide 2</li>
<li class="slide">Slide 3</li>
<li class="slide">Slide 4</li>
<li class="slide">Slide 5</li>
</ul>
<button class="controls" id="previous">Previous</button>
<button class="controls" id="next">Next</button>
<script src = "app.js" type="text/javascript"></script>
</body>
</html>
CSS
/* essential styles:these make the slideshow work
*/
#slides {
position: relative;
height: 300px;
padding: 0px;
margin: 0px;
list-style-type: none;
}
.slide {
position: absolute;
left: 0px;
top: 0px;
width: 100%;
height: 100%;
opacity: 0;
z-index: 1;
-webkit-transition: opacity 1s;
-moz-transition: opacity 1s;
-o-transition: opacity 1s;
transition: opacity 1s;
}
.showing {
opacity: 1;
z-index: 2;
}
/*non-essential styles:just for appearance; change whatever you want*/
.slide {
font-size: 40px;
padding: 40px;
box-sizing: border-box;
background: #333;
color: #fff;
}
.slide:nth-of-type(1) {
background: red;
}
.slide:nth-of-type(2) {
background: orange;
}
.slide:nth-of-type(3) {
background: green;
}
.slide:nth-of-type(4) {
background: blue;
}
.slide:nth-of-type(5) {
background: purple;
}
JS file
"use strict";
var slides = document.querySelectorAll('#slides .slide');
var currentSlide = 0;
function nextSlide() {
goToSlide(currentSlide+1);
}
function previousSlide() {
goToSlide(currentSlide-1);
}
function goToSlide(n) {
slides[currentSlide].className = 'slide';
currentSlide = (n+slides.length)%slides.length;
slides[currentSlide].className = 'slide showing';
}
var next = document.getElementById('next');
var previous = document.getElementById('previous');
next.onclick = function() {
pauseSlideshow();
nextSlide();
};
previous.onclick = function() {
pauseSlideshow();
previousSlide();
};
Just like any other text file,
.js
files have specific encoding they are saved in. This message means you are saving the.js
file with a non-UTF8
encoding (probably ASCII), and so your non-ASCII characters never even make it to the disk.While saving files from your Text Editor, you'll have to change the encoding of the file, choose UTF-8 without saving a Byte Order Mark (BOM).
Ref: https://stackoverflow.com/a/9853620/1939163 Also see this answer: https://stackoverflow.com/a/14902390/1939163