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.6k 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.
    • htilburgsH Offline
      htilburgs
      last edited by

      @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 Offline
        sdetweil
        last edited by

        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
        • htilburgsH Offline
          htilburgs
          last edited by

          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 Reply Quote 0
          • S Offline
            sdetweil @htilburgs
            last edited by

            @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

            htilburgsH 1 Reply Last reply Reply Quote 0
            • htilburgsH Offline
              htilburgs @sdetweil
              last edited by

              @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 Reply Quote 0
              • S Offline
                sdetweil @htilburgs
                last edited by

                @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

                htilburgsH 1 Reply Last reply Reply Quote 0
                • htilburgsH Offline
                  htilburgs @sdetweil
                  last edited by

                  @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
                  • First post
                    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