• Recent
  • Tags
  • Unsolved
  • Solved
  • MagicMirror² Repository
  • Documentation
  • 3rd-Party-Modules
  • Donate
  • Discord
  • Register
  • Login
MagicMirror Forum
  • Recent
  • Tags
  • Unsolved
  • Solved
  • MagicMirror² Repository
  • Documentation
  • 3rd-Party-Modules
  • Donate
  • Discord
  • Register
  • Login
A New Chapter for MagicMirror: The Community Takes the Lead
Read the statement by Michael Teeuw here.

Uncaught SyntaxError: Unexpected token return

Scheduled Pinned Locked Moved Solved Troubleshooting
9 Posts 2 Posters 2.5k Views 2 Watching
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Away
    sdetweil @htilburgs
    last edited by Mar 22, 2019, 5:50 PM

    @htilburgs said in Uncaught SyntaxError: Unexpected token return:

      }		
      return table;		
    

    u have an extra close brace, which matches up with the getDom() {
    and so, that return is just hanging out there

    Sam

    How to add modules

    learning how to use browser developers window for css changes

    1 Reply Last reply Reply Quote 0
    • H Offline
      htilburgs
      last edited by Mar 23, 2019, 10:14 AM

      @sdetweil , thanx, missed that.
      Now that this part is running the JSON data is fetched. But when I trying to show the data I get an error:

      Uncaught SyntaxError: Unexpected number
      

      This error is created by the zero in the line:
      WoonplaatsCell.innerHTML = MWB.0.plaats;

      		var MWB = this.MWB;
      
      		// creating the tablerows
      		var WoonplaatsRow = document.createElement("tr");
      		WoonplaatsRow.className = "woonplaats-row";
      		
      		var WoonplaatsCell = document.createElement("td");
      		WoonplaatsCell.className = "small";
      		WoonplaatsCell.innerHTML = MWB.0.plaats;
      		WoonplaatsRow.appendChild(WoonplaatsCell);
      		table.appendChild(WoonplaatsRow);
      

      The problem seems that I cannot use the 0 in the command.

      This is the JSON result

      object{1}
      	liveweer[1]
      		0{49}
      			alarm: "0"
      			d0neerslag: "4"
      			d0tmax: "12"
      			plaats: "Amsterdam"
      			...
      

      I used a JSON checker and it says that it’s valid JSON.
      How do I display the data from this result, if I cannot use the 0?

      (still trying to learn JS, but not afraid to ask) ☺

      1 Reply Last reply Reply Quote 0
      • S Away
        sdetweil
        last edited by Mar 23, 2019, 12:13 PM

        use a variable to hold the value

        var x = 0

        WoonplaatsCell.innerHTML = MWB.x.plaats;
        or use a literal

        WoonplaatsCell.innerHTML = MWB.[‘0’].plaats;

        Sam

        How to add modules

        learning how to use browser developers window for css changes

        1 Reply Last reply Reply Quote 0
        • H Offline
          htilburgs
          last edited by Mar 23, 2019, 1:00 PM

          No luck…
          I’ve tried both of the options:

          	var MWB = this.MWB;
          	var n = 0;
          
          	// creating the tablerows
          	var WoonplaatsRow = document.createElement("tr");
          	WoonplaatsRow.className = "woonplaats-row";
          	
          	var WoonplaatsCell = document.createElement("td");
          	WoonplaatsCell.className = "small";
          	WoonplaatsCell.innerHTML = MWB.n.plaats;
          	WoonplaatsRow.appendChild(WoonplaatsCell);
          	table.appendChild(WoonplaatsRow);
          

          Error: Uncaught (in promise) TypeError: Cannot read property ‘plaats’ of undefined

          	var MWB = this.MWB;
          
          	// creating the tablerows
          	var WoonplaatsRow = document.createElement("tr");
          	WoonplaatsRow.className = "woonplaats-row";
          	
          	var WoonplaatsCell = document.createElement("td");
          	WoonplaatsCell.className = "small";
          	WoonplaatsCell.innerHTML = MWB.['0'].plaats;
          	WoonplaatsRow.appendChild(WoonplaatsCell);
          	table.appendChild(WoonplaatsRow);
          

          Error: Uncaught SyntaxError: Unexpected token [

          So both of the options give an error.

          (still trying to learn JS, but not afraid to ask) ☺

          S 1 Reply Last reply Mar 23, 2019, 1:26 PM Reply Quote 0
          • S Away
            sdetweil @htilburgs
            last edited by Mar 23, 2019, 1:26 PM

            @htilburgs said in Uncaught SyntaxError: Unexpected token return:

            WoonplaatsCell.innerHTML = MWB.[‘0’].plaats;

            sorry, my bad, try these

            WoonplaatsCell.innerHTML = MWB[n].plaats;
            WoonplaatsCell.innerHTML = MWB['0'].plaats;
            

            Sam

            How to add modules

            learning how to use browser developers window for css changes

            H 1 Reply Last reply Mar 23, 2019, 2:02 PM Reply Quote 0
            • H Offline
              htilburgs @sdetweil
              last edited by Mar 23, 2019, 2:02 PM

              @sdetweil YES, that did the trick! Learning a lot these few days.
              Thanks again.

              Is this notation always like this if you’re working with numbers?

              (still trying to learn JS, but not afraid to ask) ☺

              S 1 Reply Last reply Mar 23, 2019, 2:21 PM Reply Quote 0
              • S Away
                sdetweil @htilburgs
                last edited by Mar 23, 2019, 2:21 PM

                @htilburgs not so much numbers, but variable data… the notation

                MWB.n.plaats
                

                means the plaats element of the n element of MWB
                so the dot notation treats the between dot things as literals…

                a number can’t be a variable name literal in this sense…
                so, you need the bracket notation [] (and remove the left side dot when u use it this way)

                Sam

                How to add modules

                learning how to use browser developers window for css changes

                H 1 Reply Last reply Mar 23, 2019, 4:13 PM Reply Quote 0
                • H Offline
                  htilburgs @sdetweil
                  last edited by Mar 23, 2019, 4:13 PM

                  @sdetweil Oké, thank you for the explanation.

                  (still trying to learn JS, but not afraid to ask) ☺

                  1 Reply Last reply Reply Quote 0
                  • 1 / 1
                  1 / 1
                  • First post
                    6/9
                    Last post
                  Enjoying MagicMirror? Please consider a donation!
                  MagicMirror created by Michael Teeuw.
                  Forum managed by Sam, technical setup by Karsten.
                  This forum is using NodeBB as its core | Contributors
                  Contact | Privacy Policy