Where does the "Missing semicolon" belong?

Sublime Text gives me the error of a missing semicolon in this part of the code, pointing to the first 'function" line as the culprit. Can anyone tell me where the semicolon goes? It doesn’t belong after the closing curly brace; that throws a warning.

	function grabFilename(filename, size, color) { 		
	if (color.length < 1) {color = "black";}
		var mainFolder = "0cars/0racing-cars"; // URL to this page
		var mainHtml = "/0racing-cars.html"; // this page
		localStorage.setItem('wpMainFolder', mainFolder);
		localStorage.setItem('wpMainHtml', mainHtml);
	    localStorage.setItem('wpName', filename);
	    localStorage.setItem('screenSize', size);
	    localStorage.setItem('bgColor', color);

Taking a wild guess (as someone more familiar with php than js), check the line before the function which is not included in your snippet.

No, that’s not it. Here is everything above the function line:

<!DOCTYPE html>
    <meta name="viewport" content="width=device-width,user-scalable=no" />
	<link rel="stylesheet" type="text/css" href="../../themes/responsive.css" />
    <link type="text/css" rel="stylesheet" media="screen" href="../../themes/jqt/theme.css" />

	<script type="text/javascript"> 
	function grabFilename(filename, size, color) {

Like @SamA74 I would like to take an even wilder guess, and I think I’m much worse with javascript.

Maybe the second line needs the assignment in double parantheses:

if ((color.length < 1)) {color = "black";}

Can’t think of anything else, Sublime Text seems to be very picky.


@Paul_Wilkins: And I just proved that.
Thanks for the “jslint.com” tip.

There is nothing wrong with the semicolons in that code.

If you want to be absolutely sure though, run it through jslint.com

For example, it is fully happy with the following tweaked code:

/*jslint browser*/
/*global localStorage, window*/
function grabFilename(filename, size, color) {
    "use strict";
    if (color.length < 1) {
        color = "black";
    var mainFolder = "0cars/0racing-cars"; // URL to this page
    var mainHtml = "/0racing-cars.html"; // this page
    localStorage.setItem("wpMainFolder", mainFolder);
    localStorage.setItem("wpMainHtml", mainHtml);
    localStorage.setItem("wpName", filename);
    localStorage.setItem("screenSize", size);
    localStorage.setItem("bgColor", color);
    window.location = "../../wp_Show.html";

Thanks, Paul. Both Sublime Text AND jslint are picky!

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.