JavaScript Error: Variable name is missing

My code keeps throwing a

SyntaxError: missing variable name
at line 17:
var drawSverige = document.getElementById('draw-sverige')

I'm struggling to understand why. The keyword "var" is clearly present before the identifier drawSverige.

!function () {
    'use strict';

    function Flag(){
        this.init = function (flag, country){
            this.flagInfo = country;
            this.htmlTag = flag;
               };
      }

        this.draw = function() {
            this.htmlTag.innerHTML = this.flagInfo;
        };


        var flagSverige = document.getElementById('flag-sverige'),
        var drawSverige = document.getElementById('draw-sverige'),

        var flagElfenbenskusten = document.getElementById('flag-elfenbenskusten'),
        var drawElfenbenskusten = document.getElementById('draw-elfenbenskusten'),

        var flagMaruritius = document.getElementById('flag-maruritius'),
        var drawMaruritius = document.getElementById('draw-maruritius'),

        var flagJapan = document.getElementById('flag-japan'),
        var drawJapan = document.getElementById('draw-japan'),

        showSverige = new Flag();
        showSverige.init(flag, '<div class="flagga1 sverige"><div class="box1"></div><div class="box2"></div><div class="box3"></div><div class="box4"></div></div>');

        var showElfenbenskusten = new Flag();
        showElfenbenskusten.init(flag, '<div class="flag elfenbenskusten"><div class="part1"></div><div class="part2"></div></div>');

        var showMaruritius = new Flag();
        showMaruritius.init(flag, '<div class="flagga2 maruritius"><div class="box1"></div><div class="box2"></div><div class="box3"></div><div class="box4"></div><div class="box5"></div></div>');

        var showJapan = new Flag();
        showJapan.init(flag, '<div class="flagga3 japan"><div class="box1"></div><div class="cirkel1"></div></div>');

        for (var flagx = [
            flagSverige,
            flagElfenbenskusten,
            flagMaruritius,
            flagJapan
            ], tot = 0; tot < flagx.length; tot++)
            flagx[tot].draw();

}();  

Answer №1

The reason for removing the var keyword after the first declaration is because a comma was used in between each declaration:

 var flagSverige = document.getElementById('flag-sverige'),
        drawSverige = document.getElementById('draw-sverige'),

        flagElfenbenskusten = document.getElementById('flag-elfenbenskusten'),
        drawElfenbenskusten = document.getElementById('draw-elfenbenskusten'),

       flagMaruritius = document.getElementById('flag-maruritius'),
       drawMaruritius = document.getElementById('draw-maruritius'),

       flagJapan = document.getElementById('flag-japan'),
       drawJapan = document.getElementById('draw-japan');

Answer №2

All your variables are terminated with a comma.

To rectify this issue, simply substitute the ',' with a ';'.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Using JavaScript to analyze and handle newlines, spaces, and the backslash character

Hello everyone, I'm hoping things are going well. I am currently working on removing newline and "\" characters from a string that I have after using JSON.stringify(). The string in question appears as follows: "[{\n \"id_profile&bs ...

Attach an event to a shape displayed on the canvas

Is there a way to bind an event to a shape that is drawn on a canvas in HTML? I tried the following code, but it throws an error. <html> <head> <script type="application/javascript"> function draw() { var canvas ...

Not all items were displayed in the dropdown menu

I'm facing an issue with creating a dropdown menu that includes animation. When I tried to open the menu, it only displays 2 items instead of the expected 5. HTML <div id="header"> <div id="logo" class="logo"> <a id="aLogo" href=" ...

Tips for saving a list of data in a responsive component using Vue 2

Currently, I am developing a web application where users can input objects into a database. The structure of these objects is predefined, but some have a data property that contains a map of strings, for instance { title: "Test", description: &qu ...

Clicking on the button will advance to the next tab rather than selecting the tab

I have this code snippet in HTML: $(document).ready(function() { $("div.bhoechie-tab-menu>div.list-group>a").click(function(e) { e.preventDefault(); $(this).siblings('a.active').removeClass("active"); $(th ...

Horizontal rule located within a table but spanning the entire width

I wrote the following code: <table> {item.awards.map((obj,i) => <tbody> <tr> <td>Name</td> <td>:</td> <td>{obj.title}</td> </tr> ...

Generating Words using JavaScript

I have been working on creating a word generator that prompts the user to input ten strings and then outputs a randomly selected one. However, instead of displaying the user input string, it is currently generating a random number. I am not encountering an ...

What is the best way to fetch and convert information from an API to display on a website?

I am encountering an issue while trying to retrieve data from an API. Below is my code with a fabricated access code. $(function () { var $data = ('#data'); $.ajax({ type: 'GET', url: 'http://api.openweathe ...

The component fails to display during my testing efforts

I am encountering a peculiar issue. In my setup, I am using jasmine 2.0, react 0.13.3, react-router 0.13.3, and various other packages. The problem lies within my test suite where it fails to findRenderedDOMComponentWithTag(). Let me provide a specific exa ...

Pressing a button will reset the input spinner in Bootstrap

Is there a way to reset the bootstrap input spinner by clicking a button? I attempted using document.getelementbyId().value = "0" and also tried using reset(), but neither method worked. Any suggestions on how to successfully reset it? function resetScor ...

Adding the ability to export CSV files from Bootstrap Table to an Angular 15 project

Struggling to incorporate the Bootstrap-table export extension into my Angular project without success so far. Visit this link for more information Any assistance or examples would be greatly appreciated. Thank you in advance! This is what I have tried ...

Is JavaScript still running despite not displaying insecure items due to IE 8 security warning?

After a user completes a transaction on my site, the confirmation page displays Google conversion tracking code in a small JavaScript snippet. This code is located on my Wordpay callback page, which pulls data from the regular site (HTTP) to the Worldpay s ...

Highlighting table column when input is selected

I am working with a table where each <td> contains an <input>. My goal is to apply the class .highlighted to all the column <td>s when an <input> is being focused on. Additionally, I want to remove this class from all other columns ...

Implementing access restrictions for modules in NodeJS

In Node, is it possible to limit access or permit access only to specific modules from a particular module? Should I consider replacing the require function and object in the global scope for this purpose? I have concerns about the security of a certain mo ...

Type of variable that is not an array

I need a quick way to check if a value is an object {} but not an array []. The code I currently have is: function isPlainObject(input) { return !Array.isArray(input) && typeof input === 'object'; } Is there a more concise method to a ...

Replace Ajax Success Function

Looking to customize the behavior of the jQuery ajax function by handling a default action upon successful execution, while still running the callback function specified in the options parameter. Essentially, I need to filter out specific tags from the res ...

The handleClose() function in React is currently writing to the console but failing to close the child element

Currently, I am in the process of creating a small online store for my personal business. Although I have limited experience with React, I believe I have managed to make some progress and might be able to complete something that is at least functional, eve ...

My React hooks are failing to properly update the state using useState

I have been encountering an issue with the code in my component where the state is not updating as expected. When I invoke the createUserList function, I can view the users in the UserList component. However, when I attempt to log the users in the UserCom ...

Is there a way in jquery or any other method that specifically detects changes only in direct child nodes?

I came across a jQuery method called DOMSubtreeModified that can detect the insertion of child nodes within a specific DOM. However, I noticed that this method detects the insertion of all child nodes, not just the immediate ones. Is there a jQuery met ...

Using JavaScript to determine the time it will take to download something

Hi everyone, I'm a beginner in javascript and I am currently working on finding the download time of a file. I have calculated the size of the file and divided it by the current time, but unfortunately, I am not getting the correct result. This is th ...